@luomus/laji-form 15.1.4 → 15.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/lib/ApiClient.d.ts +46 -0
  2. package/lib/ApiClient.js +93 -0
  3. package/lib/Context.d.ts +8 -0
  4. package/lib/Context.js +18 -0
  5. package/lib/ReactContext.d.ts +7 -0
  6. package/lib/ReactContext.js +5 -0
  7. package/lib/components/BaseComponent.d.ts +9 -0
  8. package/lib/components/BaseComponent.js +29 -0
  9. package/lib/components/LajiForm.d.ts +221 -0
  10. package/lib/components/LajiForm.js +616 -0
  11. package/lib/components/VirtualSchemaField.d.ts +42 -0
  12. package/lib/components/VirtualSchemaField.js +74 -0
  13. package/lib/components/components.d.ts +119 -0
  14. package/lib/components/components.js +606 -0
  15. package/lib/components/fields/AnnotationField.d.ts +34 -0
  16. package/lib/components/fields/AnnotationField.js +242 -0
  17. package/lib/components/fields/AnyToBooleanField.d.ts +18 -0
  18. package/lib/components/fields/AnyToBooleanField.js +20 -0
  19. package/lib/components/fields/ArrayBulkField.d.ts +23 -0
  20. package/lib/components/fields/ArrayBulkField.js +82 -0
  21. package/lib/components/fields/ArrayCombinerField.d.ts +36 -0
  22. package/lib/components/fields/ArrayCombinerField.js +138 -0
  23. package/lib/components/fields/ArrayField.d.ts +39 -0
  24. package/lib/components/fields/ArrayField.js +148 -0
  25. package/lib/components/fields/AsArrayField.d.ts +292 -0
  26. package/lib/components/fields/AsArrayField.js +38 -0
  27. package/lib/components/fields/AudioArrayField.d.ts +22 -0
  28. package/lib/components/fields/AudioArrayField.js +100 -0
  29. package/lib/components/fields/AutoArrayField.d.ts +24 -0
  30. package/lib/components/fields/AutoArrayField.js +56 -0
  31. package/lib/components/fields/AutosuggestField.d.ts +69 -0
  32. package/lib/components/fields/AutosuggestField.js +299 -0
  33. package/lib/components/fields/CombinedValueDisplayField.d.ts +41 -0
  34. package/lib/components/fields/CombinedValueDisplayField.js +100 -0
  35. package/lib/components/fields/ConditionalOnChangeField.d.ts +42 -0
  36. package/lib/components/fields/ConditionalOnChangeField.js +107 -0
  37. package/lib/components/fields/ConditionalUiSchemaField.d.ts +123 -0
  38. package/lib/components/fields/ConditionalUiSchemaField.js +143 -0
  39. package/lib/components/fields/ContextInjectionField.d.ts +24 -0
  40. package/lib/components/fields/ContextInjectionField.js +68 -0
  41. package/lib/components/fields/DataLeakerField.d.ts +40 -0
  42. package/lib/components/fields/DataLeakerField.js +68 -0
  43. package/lib/components/fields/DefaultValueArrayField.d.ts +34 -0
  44. package/lib/components/fields/DefaultValueArrayField.js +59 -0
  45. package/lib/components/fields/DependentBooleanField.d.ts +38 -0
  46. package/lib/components/fields/DependentBooleanField.js +87 -0
  47. package/lib/components/fields/DependentDisableField.d.ts +35 -0
  48. package/lib/components/fields/DependentDisableField.js +71 -0
  49. package/lib/components/fields/EnumRangeArrayField.d.ts +27 -0
  50. package/lib/components/fields/EnumRangeArrayField.js +115 -0
  51. package/lib/components/fields/ExtraLabelRowField.d.ts +38 -0
  52. package/lib/components/fields/ExtraLabelRowField.js +100 -0
  53. package/lib/components/fields/FakePropertyField.d.ts +18 -0
  54. package/lib/components/fields/FakePropertyField.js +48 -0
  55. package/lib/components/fields/FilterArrayField.d.ts +73 -0
  56. package/lib/components/fields/FilterArrayField.js +121 -0
  57. package/lib/components/fields/FlatField.d.ts +29 -0
  58. package/lib/components/fields/FlatField.js +171 -0
  59. package/lib/components/fields/GeocoderField.d.ts +47 -0
  60. package/lib/components/fields/GeocoderField.js +372 -0
  61. package/lib/components/fields/GridLayoutField.d.ts +18 -0
  62. package/lib/components/fields/GridLayoutField.js +32 -0
  63. package/lib/components/fields/HiddenField.d.ts +10 -0
  64. package/lib/components/fields/HiddenField.js +11 -0
  65. package/lib/components/fields/ImageArrayField.d.ts +172 -0
  66. package/lib/components/fields/ImageArrayField.js +699 -0
  67. package/lib/components/fields/ImageDisplayField.d.ts +18 -0
  68. package/lib/components/fields/ImageDisplayField.js +44 -0
  69. package/lib/components/fields/InitiallyHiddenField.d.ts +21 -0
  70. package/lib/components/fields/InitiallyHiddenField.js +58 -0
  71. package/lib/components/fields/InjectDefaultValueField.d.ts +37 -0
  72. package/lib/components/fields/InjectDefaultValueField.js +68 -0
  73. package/lib/components/fields/InjectField.d.ts +46 -0
  74. package/lib/components/fields/InjectField.js +88 -0
  75. package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +25 -0
  76. package/lib/components/fields/InputWithDefaultValueButtonField.js +61 -0
  77. package/lib/components/fields/LocalityField.d.ts +22 -0
  78. package/lib/components/fields/LocalityField.js +94 -0
  79. package/lib/components/fields/LocationChooserField.d.ts +27 -0
  80. package/lib/components/fields/LocationChooserField.js +440 -0
  81. package/lib/components/fields/MapArrayField.d.ts +78 -0
  82. package/lib/components/fields/MapArrayField.js +1783 -0
  83. package/lib/components/fields/MapField.d.ts +48 -0
  84. package/lib/components/fields/MapField.js +434 -0
  85. package/lib/components/fields/MultiAnyToBooleanField.d.ts +25 -0
  86. package/lib/components/fields/MultiAnyToBooleanField.js +100 -0
  87. package/lib/components/fields/MultiArrayField.d.ts +53 -0
  88. package/lib/components/fields/MultiArrayField.js +224 -0
  89. package/lib/components/fields/MultiLanguageField.d.ts +13 -0
  90. package/lib/components/fields/MultiLanguageField.js +52 -0
  91. package/lib/components/fields/MultiTagArrayField.d.ts +36 -0
  92. package/lib/components/fields/MultiTagArrayField.js +142 -0
  93. package/lib/components/fields/NamedPlaceChooserField.d.ts +29 -0
  94. package/lib/components/fields/NamedPlaceChooserField.js +380 -0
  95. package/lib/components/fields/NamedPlaceSaverField.d.ts +29 -0
  96. package/lib/components/fields/NamedPlaceSaverField.js +237 -0
  97. package/lib/components/fields/NestField.d.ts +148 -0
  98. package/lib/components/fields/NestField.js +289 -0
  99. package/lib/components/fields/ObjectField.d.ts +2 -0
  100. package/lib/components/fields/ObjectField.js +119 -0
  101. package/lib/components/fields/PdfArrayField.d.ts +21 -0
  102. package/lib/components/fields/PdfArrayField.js +40 -0
  103. package/lib/components/fields/PrefillingArrayField.d.ts +22 -0
  104. package/lib/components/fields/PrefillingArrayField.js +65 -0
  105. package/lib/components/fields/SchemaField.d.ts +7 -0
  106. package/lib/components/fields/SchemaField.js +109 -0
  107. package/lib/components/fields/ScopeField.d.ts +85 -0
  108. package/lib/components/fields/ScopeField.js +521 -0
  109. package/lib/components/fields/SectionArrayField.d.ts +38 -0
  110. package/lib/components/fields/SectionArrayField.js +618 -0
  111. package/lib/components/fields/SelectTreeField.d.ts +39 -0
  112. package/lib/components/fields/SelectTreeField.js +143 -0
  113. package/lib/components/fields/SingleActiveArrayField.d.ts +49 -0
  114. package/lib/components/fields/SingleActiveArrayField.js +974 -0
  115. package/lib/components/fields/SingleItemArrayField.d.ts +15 -0
  116. package/lib/components/fields/SingleItemArrayField.js +60 -0
  117. package/lib/components/fields/SortArrayField.d.ts +73 -0
  118. package/lib/components/fields/SortArrayField.js +351 -0
  119. package/lib/components/fields/SplitField.d.ts +28 -0
  120. package/lib/components/fields/SplitField.js +65 -0
  121. package/lib/components/fields/StringToArrayField.d.ts +24 -0
  122. package/lib/components/fields/StringToArrayField.js +48 -0
  123. package/lib/components/fields/SumField.d.ts +35 -0
  124. package/lib/components/fields/SumField.js +83 -0
  125. package/lib/components/fields/TableField.d.ts +18 -0
  126. package/lib/components/fields/TableField.js +136 -0
  127. package/lib/components/fields/TagArrayField.d.ts +38 -0
  128. package/lib/components/fields/TagArrayField.js +128 -0
  129. package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +26 -0
  130. package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +81 -0
  131. package/lib/components/fields/UiFieldApplierField.d.ts +30 -0
  132. package/lib/components/fields/UiFieldApplierField.js +106 -0
  133. package/lib/components/fields/UiFieldMapperArrayField.d.ts +42 -0
  134. package/lib/components/fields/UiFieldMapperArrayField.js +121 -0
  135. package/lib/components/fields/UnitCountShorthandField.d.ts +22 -0
  136. package/lib/components/fields/UnitCountShorthandField.js +149 -0
  137. package/lib/components/fields/UnitListShorthandArrayField.d.ts +26 -0
  138. package/lib/components/fields/UnitListShorthandArrayField.js +108 -0
  139. package/lib/components/fields/UnitShorthandField.d.ts +32 -0
  140. package/lib/components/fields/UnitShorthandField.js +220 -0
  141. package/lib/components/templates/ArrayFieldTemplate.d.ts +85 -0
  142. package/lib/components/templates/ArrayFieldTemplate.js +416 -0
  143. package/lib/components/templates/BaseInputTemplate.d.ts +11 -0
  144. package/lib/components/templates/BaseInputTemplate.js +80 -0
  145. package/lib/components/templates/DescriptionField.d.ts +1 -0
  146. package/lib/components/templates/DescriptionField.js +37 -0
  147. package/lib/components/templates/ErrorListTemplate.d.ts +9 -0
  148. package/lib/components/templates/ErrorListTemplate.js +95 -0
  149. package/lib/components/templates/FieldTemplate.d.ts +6 -0
  150. package/lib/components/templates/FieldTemplate.js +112 -0
  151. package/lib/components/templates/ObjectFieldTemplate.d.ts +7 -0
  152. package/lib/components/templates/ObjectFieldTemplate.js +66 -0
  153. package/lib/components/templates/TitleField.d.ts +9 -0
  154. package/lib/components/templates/TitleField.js +51 -0
  155. package/lib/components/widgets/AnyToBooleanWidget.d.ts +20 -0
  156. package/lib/components/widgets/AnyToBooleanWidget.js +49 -0
  157. package/lib/components/widgets/AutosuggestWidget.d.ts +66 -0
  158. package/lib/components/widgets/AutosuggestWidget.js +1127 -0
  159. package/lib/components/widgets/CheckboxWidget.d.ts +37 -0
  160. package/lib/components/widgets/CheckboxWidget.js +139 -0
  161. package/lib/components/widgets/DateTimeWidget.d.ts +62 -0
  162. package/lib/components/widgets/DateTimeWidget.js +251 -0
  163. package/lib/components/widgets/DateWidget.d.ts +23 -0
  164. package/lib/components/widgets/DateWidget.js +41 -0
  165. package/lib/components/widgets/HiddenWidget.d.ts +15 -0
  166. package/lib/components/widgets/HiddenWidget.js +19 -0
  167. package/lib/components/widgets/ImageSelectWidget.d.ts +14 -0
  168. package/lib/components/widgets/ImageSelectWidget.js +57 -0
  169. package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +43 -0
  170. package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +237 -0
  171. package/lib/components/widgets/InputGroupWidget.d.ts +21 -0
  172. package/lib/components/widgets/InputGroupWidget.js +36 -0
  173. package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +21 -0
  174. package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +47 -0
  175. package/lib/components/widgets/NumberWidget.d.ts +13 -0
  176. package/lib/components/widgets/NumberWidget.js +21 -0
  177. package/lib/components/widgets/PlainTextWidget.d.ts +12 -0
  178. package/lib/components/widgets/PlainTextWidget.js +24 -0
  179. package/lib/components/widgets/SelectWidget.d.ts +52 -0
  180. package/lib/components/widgets/SelectWidget.js +158 -0
  181. package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +19 -0
  182. package/lib/components/widgets/SeparatedDateTimeWidget.js +59 -0
  183. package/lib/components/widgets/TaxonImageWidget.d.ts +13 -0
  184. package/lib/components/widgets/TaxonImageWidget.js +30 -0
  185. package/lib/components/widgets/TextSelectWidget.d.ts +25 -0
  186. package/lib/components/widgets/TextSelectWidget.js +94 -0
  187. package/lib/components/widgets/TextareaWidget.d.ts +32 -0
  188. package/lib/components/widgets/TextareaWidget.js +87 -0
  189. package/lib/components/widgets/TimeWidget.d.ts +11 -0
  190. package/lib/components/widgets/TimeWidget.js +19 -0
  191. package/lib/components/widgets/URLWidget.d.ts +14 -0
  192. package/lib/components/widgets/URLWidget.js +12 -0
  193. package/lib/components/widgets/UpperCaseWidget.d.ts +13 -0
  194. package/lib/components/widgets/UpperCaseWidget.js +21 -0
  195. package/lib/index.d.ts +20 -0
  196. package/lib/index.js +50 -0
  197. package/lib/services/blocker-service.d.ts +11 -0
  198. package/lib/services/blocker-service.js +55 -0
  199. package/lib/services/custom-event-service.d.ts +17 -0
  200. package/lib/services/custom-event-service.js +35 -0
  201. package/lib/services/dom-id-service.d.ts +8 -0
  202. package/lib/services/dom-id-service.js +30 -0
  203. package/lib/services/focus-service.d.ts +13 -0
  204. package/lib/services/focus-service.js +60 -0
  205. package/lib/services/id-service.d.ts +22 -0
  206. package/lib/services/id-service.js +130 -0
  207. package/lib/services/key-handler-service.d.ts +56 -0
  208. package/lib/services/key-handler-service.js +184 -0
  209. package/lib/services/root-instance-service.d.ts +25 -0
  210. package/lib/services/root-instance-service.js +49 -0
  211. package/lib/services/settings-service.d.ts +34 -0
  212. package/lib/services/settings-service.js +154 -0
  213. package/lib/services/singleton-map-service.d.ts +23 -0
  214. package/lib/services/singleton-map-service.js +44 -0
  215. package/lib/services/submit-hook-service.d.ts +24 -0
  216. package/lib/services/submit-hook-service.js +73 -0
  217. package/lib/styles.d.ts +1 -0
  218. package/lib/styles.js +4 -0
  219. package/lib/themes/bs3.d.ts +3 -0
  220. package/lib/themes/bs3.js +133 -0
  221. package/lib/themes/bs5.d.ts +3 -0
  222. package/lib/themes/bs5.js +111 -0
  223. package/lib/themes/glyphicon-fa-mapping.d.ts +3 -0
  224. package/lib/themes/glyphicon-fa-mapping.js +271 -0
  225. package/lib/themes/stub.d.ts +3 -0
  226. package/lib/themes/stub.js +82 -0
  227. package/lib/themes/theme.d.ts +233 -0
  228. package/lib/themes/theme.js +2 -0
  229. package/lib/translations.json +847 -0
  230. package/lib/utils.d.ts +167 -0
  231. package/lib/utils.js +1185 -0
  232. package/lib/validation.d.ts +7 -0
  233. package/lib/validation.js +141 -0
  234. package/package.json +2 -2
  235. package/patches/protractor++webdriver-manager+12.1.8.patch +0 -20395
@@ -0,0 +1,699 @@
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 __rest = (this && this.__rest) || function (s, e) {
9
+ var t = {};
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
11
+ t[p] = s[p];
12
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
13
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
14
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
15
+ t[p[i]] = s[p[i]];
16
+ }
17
+ return t;
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.Thumbnail = exports.MediaArrayField = void 0;
21
+ const React = require("react");
22
+ const PropTypes = require("prop-types");
23
+ const immutability_helper_1 = require("immutability-helper");
24
+ const Context_1 = require("../../Context");
25
+ const react_dropzone_1 = require("react-dropzone");
26
+ const components_1 = require("../components");
27
+ const LajiForm_1 = require("../LajiForm");
28
+ const utils_1 = require("../../utils");
29
+ const BaseComponent_1 = require("../BaseComponent");
30
+ const Spinner = require("react-spinner");
31
+ const exif = require("exif-js");
32
+ const utils_2 = require("@luomus/laji-map/lib/utils");
33
+ const moment = require("moment");
34
+ const ReactContext_1 = require("../../ReactContext");
35
+ const utils_3 = require("@rjsf/utils");
36
+ function toDecimal(number) {
37
+ if (!number)
38
+ return undefined;
39
+ return number[0].numerator + number[1].numerator /
40
+ (60 * number[1].denominator) + number[2].numerator / (3600 * number[2].denominator);
41
+ }
42
+ let mediaUuid = 0;
43
+ let ImageArrayField = class ImageArrayField extends React.Component {
44
+ constructor() {
45
+ super(...arguments);
46
+ this.ALLOWED_FILE_TYPES = ["image/jpeg", "image/png", "image/bmp", "image/tiff", "image/gif"];
47
+ this.ACCEPT_FILE_TYPES = ["image/*"];
48
+ this.MAX_FILE_SIZE = 20000000;
49
+ this.KEY = "IMAGE";
50
+ this.ENDPOINT = "images";
51
+ this.GLYPH = "camera";
52
+ this.TRANSLATION_TAKE_NEW = "TakeNewPhoto";
53
+ this.TRANSLATION_SELECT_FILE = "SelectPhoto";
54
+ this.TRANSLATION_NO_MEDIA = "NoPhoto";
55
+ this.CONTAINER_CLASS = "images-container";
56
+ this.METADATA_FORM_ID = "JX.111712";
57
+ this.renderMedia = (id) => React.createElement(Thumbnail, { id: id, apiClient: this.props.formContext.apiClient });
58
+ this.renderLoadingMedia = (id) => React.createElement(Thumbnail, { dataURL: id, loading: true, apiClient: this.props.formContext.apiClient });
59
+ this.onMediaClick = (i) => this.openModalFor(i);
60
+ this.renderModalMedia = () => React.createElement("img", { src: this.state.modalMediaSrc });
61
+ }
62
+ formatValue(value, options, props) {
63
+ const { translations } = props.formContext;
64
+ return value && value.length
65
+ ? `${value.length} ${translations.HowManyPhotos}`
66
+ : null;
67
+ }
68
+ };
69
+ ImageArrayField = __decorate([
70
+ MediaArrayField
71
+ ], ImageArrayField);
72
+ exports.default = ImageArrayField;
73
+ function MediaArrayField(ComposedComponent) {
74
+ let MediaArrayField = class MediaArrayField extends ComposedComponent {
75
+ constructor(...args) {
76
+ super(...args);
77
+ this.deprecatedOptions = {
78
+ imageAddModal: "addModal",
79
+ autoOpenImageAddModal: "autoOpenAddModal"
80
+ };
81
+ this.addMediaContainerRef = React.createRef();
82
+ this.getOptions = (uiSchema) => {
83
+ let options = utils_1.getUiOptions(uiSchema);
84
+ Object.keys(this.deprecatedOptions).forEach(deprecated => {
85
+ if (options[deprecated] !== undefined) {
86
+ options = Object.assign(Object.assign({}, options), { [this.deprecatedOptions[deprecated]]: options[deprecated] });
87
+ }
88
+ });
89
+ return options;
90
+ };
91
+ this.onDragEnter = () => { this.setState({ dragging: true }); };
92
+ this.onDragLeave = () => { this.setState({ dragging: false }); };
93
+ this.onDrop = (files) => {
94
+ this.state.dragging && this.setState({ dragging: false });
95
+ this.onFileFormChange(files);
96
+ };
97
+ this.defaultOnClick = () => {
98
+ const { addModal } = utils_1.getUiOptions(this.props.uiSchema);
99
+ this.setState({ addModal });
100
+ };
101
+ this.onKeyDown = this.props.formContext.utils.keyboardClick(() => {
102
+ var _a;
103
+ const input = (_a = this.addMediaContainerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector("input");
104
+ const { addModal } = utils_1.getUiOptions(this.props.uiSchema);
105
+ addModal ? this.defaultOnClick() : input === null || input === void 0 ? void 0 : input.click();
106
+ });
107
+ this.renderMedias = () => {
108
+ const { disabled, readonly } = this.props;
109
+ const { deleteConfirmPlacement = "top" } = utils_1.getUiOptions(this.props.uiSchema);
110
+ return (this.props.formData || []).map((item, i) => (React.createElement("div", { key: i, className: "media-container" },
111
+ React.createElement("a", { onClick: this.onMediaClick(i) }, this.renderMedia(item, i)),
112
+ React.createElement(components_1.DeleteButton, { corner: true, confirm: true, confirmPlacement: deleteConfirmPlacement, translations: this.props.formContext.translations, onClick: this.onMediaRmClick(i), disabled: disabled || readonly, id: `${this.props.idSchema.$id}_${i}` }))));
113
+ };
114
+ this.renderLoadingMedias = () => {
115
+ const containerId = this.getContainerId();
116
+ return (this.state.tmpMedias || []).map((item, i) => {
117
+ const medias = this._context.tmpMedias[containerId];
118
+ if (!medias || !medias[item])
119
+ return null;
120
+ return (React.createElement("div", { key: i, className: "media-container" },
121
+ React.createElement("a", null, this.renderLoadingMedia(medias[item]))));
122
+ });
123
+ };
124
+ this.openModalFor = (i) => () => {
125
+ const item = this.props.formData[i];
126
+ this.setState({ metadataModalOpen: i });
127
+ this.fetching = item;
128
+ this.apiClient.fetch(`/${this.ENDPOINT}/${item}`).then((response) => {
129
+ if (response.id !== this.fetching)
130
+ return;
131
+ this._context.metadatas[item] = response;
132
+ this.setState({ modalIdx: i, modalMediaSrc: response.fullURL, modalMetadata: this._context.metadatas[item] });
133
+ });
134
+ };
135
+ this.onMediaRmClick = (i) => () => {
136
+ const id = this.props.formData[i];
137
+ this.props.onChange(immutability_helper_1.default(this.props.formData, { $splice: [[i, 1]] }));
138
+ this.apiClient.fetch(`/${this.ENDPOINT}/${id}`, undefined, {
139
+ method: "DELETE",
140
+ failSilently: true
141
+ });
142
+ };
143
+ this.hideMetadataModal = () => this.setState({ metadataModalOpen: false, metadataSaveSuccess: undefined });
144
+ this.onMetadataFormChange = (formData) => this.setState({ modalMetadata: formData });
145
+ this.renderMetadataModal = () => {
146
+ const { metadataModalOpen, modalIdx, modalMetadata, metadataSaveSuccess } = this.state;
147
+ const { lang, translations } = this.props.registry.formContext;
148
+ const metadataForm = this.state.metadataForm || {};
149
+ if (typeof metadataModalOpen === "number" && !this.state.metadataForm) {
150
+ this.apiClient.fetchCached(`/forms/${this.METADATA_FORM_ID}`, { lang, format: "schema" })
151
+ .then(metadataForm => {
152
+ if (this.mounted) {
153
+ this.setState({ metadataForm });
154
+ }
155
+ });
156
+ }
157
+ const { Previous, Next } = this.props.formContext.translations;
158
+ const isOpen = modalIdx === metadataModalOpen && modalMetadata && metadataForm.schema;
159
+ const uiSchema = isOpen ? Object.assign(Object.assign({}, metadataForm.uiSchema), { "ui:shortcuts": Object.assign(Object.assign({}, (metadataForm.uiSchema["ui:shorcuts"] || {})), this.props.formContext.services.keyHandler.shortcuts), "ui:disabled": this.props.disabled, "ui:readonly": this.props.readonly }) : undefined;
160
+ const { metadataModal = true } = utils_1.getUiOptions(this.props.uiSchema);
161
+ const { Modal, Alert, Pager } = this.context.theme;
162
+ return typeof metadataModalOpen === "number" ?
163
+ React.createElement(Modal, { dialogClassName: "laji-form media-modal", show: true, onHide: this.hideMetadataModal },
164
+ React.createElement(Modal.Header, { closeButton: true },
165
+ React.createElement("br", null),
166
+ React.createElement(Pager, null,
167
+ React.createElement(Pager.Item, { previous: true, onClick: this.openModalFor(metadataModalOpen - 1), disabled: metadataModalOpen <= 0 },
168
+ "\u2190 ",
169
+ Previous),
170
+ React.createElement(Pager.Item, { next: true, onClick: this.openModalFor(metadataModalOpen + 1), disabled: metadataModalOpen >= this.props.formData.length - 1 },
171
+ Next,
172
+ " \u2192"))),
173
+ React.createElement(Modal.Body, null,
174
+ React.createElement("div", { className: `laji-form${metadataModal ? " media-modal-content" : ""}` }, isOpen
175
+ ? React.createElement(React.Fragment, null,
176
+ this.renderModalMedia(modalIdx),
177
+ metadataModal && React.createElement(LajiForm_1.default, Object.assign({}, metadataForm, { uiSchema: uiSchema, formData: modalMetadata, onChange: this.onMetadataFormChange, onSubmit: this.onMediaMetadataUpdate, submitText: translations.Save, lang: lang, apiClient: this.props.formContext.apiClient.apiClient, uiSchemaContext: this.props.formContext.uiSchemaContext, showShortcutButton: false }), (metadataSaveSuccess !== undefined) ? (React.createElement(Alert, { variant: metadataSaveSuccess ? "success" : "danger" }, translations[metadataSaveSuccess ? "SaveSuccess" : "SaveFail"])) : null))
178
+ : React.createElement(Spinner, null)))) : null;
179
+ };
180
+ this.onHideMediaAddModal = () => this.setState({ addModal: undefined }, () => {
181
+ this.parseExif([]);
182
+ });
183
+ this.renderMediaAddModal = () => {
184
+ const { disabled, readonly } = this.props;
185
+ const { addModal } = this.state;
186
+ const { labels: { cancel } = { cancel: undefined } } = (utils_1.isObject(addModal) ? addModal : {});
187
+ const { translations } = this.props.formContext;
188
+ if (!addModal)
189
+ return null;
190
+ const { Modal } = this.context.theme;
191
+ return (React.createElement(Modal, { dialogClassName: "laji-form media-add-modal", show: true, onHide: this.onHideMediaAddModal },
192
+ React.createElement(Modal.Header, { closeButton: true }),
193
+ React.createElement(Modal.Body, null,
194
+ [
195
+ ["environment",
196
+ this.TRANSLATION_TAKE_NEW
197
+ ],
198
+ [
199
+ undefined,
200
+ this.TRANSLATION_SELECT_FILE
201
+ ]
202
+ ].map(([captureMethod, label]) => React.createElement(react_dropzone_1.default, { key: captureMethod || "", accept: this.ACCEPT_FILE_TYPES, onDrop: this.onDrop, disabled: readonly || disabled }, ({ getRootProps, getInputProps }) => {
203
+ return (React.createElement("div", Object.assign({ className: "btn-block" }, getRootProps()),
204
+ React.createElement("input", Object.assign({}, getInputProps(), { capture: captureMethod })),
205
+ React.createElement(components_1.Button, { block: true, disabled: readonly || disabled }, label ? translations[label] : undefined)));
206
+ })),
207
+ React.createElement(components_1.Button, { className: "cancel", block: true, onClick: this.onHideMediaAddModal }, cancel || translations[this.TRANSLATION_NO_MEDIA]))));
208
+ };
209
+ this.onAlertOk = () => {
210
+ this.setState({ alert: false, alertMsg: undefined });
211
+ };
212
+ this.parseExif = (files) => {
213
+ const { exifParsers = [] } = utils_1.getUiOptions(this.props.uiSchema);
214
+ if (!exifParsers)
215
+ return;
216
+ const found = exifParsers.reduce((found, { parse }) => {
217
+ found[parse] = false;
218
+ return found;
219
+ }, {});
220
+ return files.reduce((promise, file) => {
221
+ if (Object.keys(found).every(k => found[k])) {
222
+ return promise;
223
+ }
224
+ return promise.then(found => new Promise(resolve => {
225
+ exif.getData(file, function () {
226
+ if ("geometry" in found)
227
+ try {
228
+ const coordinates = ["GPSLongitude", "GPSLatitude"].map(tag => toDecimal(exif.getTag(this, tag)));
229
+ const rawDatum = exif.getTag(this, "GPSMapDatum");
230
+ const datum = typeof rawDatum === "string"
231
+ ? rawDatum.trim().toUpperCase()
232
+ : undefined;
233
+ if ((!datum || datum === "WGS-84" || datum === "WGS84") && utils_2.validateLatLng(coordinates, utils_2.wgs84Validator)) {
234
+ found.geometry = {
235
+ type: "Point",
236
+ coordinates
237
+ };
238
+ }
239
+ }
240
+ catch (e) {
241
+ console.info("Reading GPS from EXIF failed", e);
242
+ }
243
+ const readDateFromFile = () => {
244
+ if (file.lastModified) {
245
+ const momentDate = moment(file.lastModified);
246
+ if (momentDate.isValid()) {
247
+ const date = momentDate.format("YYYY-MM-DDTHH:mm");
248
+ if (date) {
249
+ found.date = date;
250
+ }
251
+ }
252
+ }
253
+ };
254
+ if ("date" in found) {
255
+ try {
256
+ const rawDate = exif.getTag(this, "DateTimeOriginal");
257
+ const momentDate = moment(rawDate, "YYYY:MM:DD HH:mm:ss");
258
+ if (momentDate.isValid()) {
259
+ found.date = momentDate.format("YYYY-MM-DDTHH:mm");
260
+ }
261
+ else {
262
+ readDateFromFile();
263
+ }
264
+ }
265
+ catch (e) {
266
+ console.info("Reading date from EXIF failed, trying to read from file", e);
267
+ readDateFromFile();
268
+ }
269
+ }
270
+ else {
271
+ readDateFromFile();
272
+ }
273
+ resolve(found);
274
+ });
275
+ }));
276
+ }, Promise.resolve(found)).then((found) => {
277
+ let { registry } = this.props;
278
+ const lajiFormInstance = this.props.formContext.services.rootInstance;
279
+ const schema = lajiFormInstance.getSchema();
280
+ let formData = lajiFormInstance.getFormData();
281
+ exifParsers.filter((f) => f.type === "event" || found[f.parse]).forEach(({ field, parse, type, eventName }) => {
282
+ if (type === "mutate") {
283
+ formData = utils_1.updateFormDataWithJSONPointer({ formData, schema, registry }, found[parse], field);
284
+ }
285
+ if (type === "event") {
286
+ this.props.formContext.services.customEvents.send(`root_${utils_1.JSONPointerToId(field)}`, eventName, found[parse], undefined, { bubble: false });
287
+ }
288
+ });
289
+ return formData;
290
+ });
291
+ };
292
+ this.sideEffects = (formData) => {
293
+ const lajiFormInstance = this.props.formContext.services.rootInstance;
294
+ const schema = lajiFormInstance.getSchema();
295
+ const lajiFormFormData = lajiFormInstance.getFormData();
296
+ const { sideEffects } = utils_1.getUiOptions(this.props.uiSchema);
297
+ if (sideEffects) {
298
+ const thisPath = utils_1.idSchemaIdToJSONPointer(this.props.idSchema.$id);
299
+ const containerPath = thisPath.replace(/^(\/.*)\/.*$/, "$1");
300
+ const parseRelativePaths = (path, containerPath) => {
301
+ while ((path.match(/\/\.\./g) || []).length > 1) {
302
+ containerPath = containerPath.replace(/^(\/.*)\/.*$/, "$1");
303
+ path = path.replace(/^(.*)\/\.\.(.*)/, "$1$2");
304
+ }
305
+ return path.replace(/^(.*)\/\.\.(.*)/, `$1${containerPath}$2`);
306
+ };
307
+ formData = Object.keys(sideEffects).reduce((formData, field) => {
308
+ const jsonPointer = parseRelativePaths(field, containerPath);
309
+ return !utils_1.isDefaultData(utils_1.parseJSONPointer(formData, jsonPointer), utils_1.parseSchemaFromFormDataPointer(schema, jsonPointer))
310
+ ? formData
311
+ : utils_1.updateFormDataWithJSONPointer({ schema, registry: this.props.registry, formData }, sideEffects[field], parseRelativePaths(field, containerPath));
312
+ }, formData);
313
+ }
314
+ if (formData !== lajiFormFormData) {
315
+ lajiFormInstance.onChange(formData);
316
+ }
317
+ };
318
+ this.onFileFormChange = (files) => {
319
+ var _a;
320
+ if (this.state.addModal) {
321
+ this.setState({ addModal: undefined });
322
+ }
323
+ (_a = this.parseExif(files)) === null || _a === void 0 ? void 0 : _a.then(this.sideEffects);
324
+ const id = this.getContainerId();
325
+ const lajiFormInstance = this.props.formContext.services.rootInstance;
326
+ const saveAndOnChange = () => this.saveMedias(files).then(mediaIds => {
327
+ if (!lajiFormInstance.isMounted() || !mediaIds) {
328
+ return;
329
+ }
330
+ let pointer = this.props.formContext.services.ids.getJSONPointerFromLajiFormIdAndFormDataAndIdSchemaId(this.props.idSchema.$id, id);
331
+ if (!this.mounted && !pointer) {
332
+ return;
333
+ }
334
+ const newFormData = [
335
+ ...(this.mounted
336
+ ? this.props.formData || []
337
+ : utils_1.parseJSONPointer(lajiFormInstance.getFormData(), pointer) || []),
338
+ ...mediaIds
339
+ ];
340
+ if (!lajiFormInstance.isMounted())
341
+ return;
342
+ if ((this.mounted || id === "root") && id === this.getContainerId()) {
343
+ this.props.onChange(newFormData);
344
+ // Settimeout because the resource is undefined 404 if fetched right away.
345
+ setTimeout(() => {
346
+ if (!this.mounted)
347
+ return;
348
+ const { autoOpenMetadataModal = false } = utils_1.getUiOptions(this.props.uiSchema);
349
+ let shouldOpenMetadataModal = autoOpenMetadataModal;
350
+ if (shouldOpenMetadataModal) {
351
+ this.openModalFor(newFormData.length - mediaIds.length)();
352
+ }
353
+ }, 0);
354
+ return;
355
+ }
356
+ pointer = this.props.formContext.services.ids.getJSONPointerFromLajiFormIdAndFormDataAndIdSchemaId(this.props.idSchema.$id, id);
357
+ lajiFormInstance.onChange(utils_1.updateSafelyWithJSONPointer(lajiFormInstance.getFormData(), newFormData, pointer));
358
+ });
359
+ this.props.formContext.services.submitHooks.add(this.props, saveAndOnChange);
360
+ };
361
+ this.getContainerId = () => {
362
+ const { _parentLajiFormId = "root" } = this.props.formContext;
363
+ return _parentLajiFormId;
364
+ };
365
+ this.addNameToDataURL = (dataURL, name) => {
366
+ return dataURL.replace(";base64", `;name=${name};base64`);
367
+ };
368
+ this.processFiles = (files) => {
369
+ return Promise.all([].map.call(files, this.processFile));
370
+ };
371
+ this.processFile = (file) => {
372
+ const { name, size, type } = file;
373
+ return new Promise(resolve => {
374
+ const reader = new window.FileReader();
375
+ reader.onload = event => {
376
+ var _a;
377
+ resolve({
378
+ dataURL: this.addNameToDataURL((_a = event.target) === null || _a === void 0 ? void 0 : _a.result, name),
379
+ name,
380
+ size,
381
+ type
382
+ });
383
+ };
384
+ reader.readAsDataURL(file);
385
+ });
386
+ };
387
+ this.onMediaMetadataUpdate = ({ formData }) => {
388
+ this.props.formContext.services.blocker.push();
389
+ this.apiClient.fetch(`/${this.ENDPOINT}/${formData.id}`, undefined, {
390
+ method: "PUT",
391
+ headers: {
392
+ "accept": "application/json",
393
+ "content-type": "application/json"
394
+ },
395
+ body: JSON.stringify(formData)
396
+ }).then(() => {
397
+ this.props.formContext.services.blocker.pop();
398
+ const notify = () => this.props.formContext.notifier.success(this.props.formContext.translations.SaveSuccess);
399
+ if (this.mounted) {
400
+ this.setState({ metadataModalOpen: false }, notify);
401
+ }
402
+ else {
403
+ notify();
404
+ }
405
+ }).catch(() => {
406
+ this.props.formContext.services.blocker.pop();
407
+ this.mounted && this.setState({ metadataSaveSuccess: false });
408
+ });
409
+ };
410
+ this.getMetadataPromise = () => {
411
+ let mediaMetadata = this.props.formContext.mediaMetadata
412
+ || { intellectualRights: "MZ.intellectualRightsARR" };
413
+ const MACode = this.props.formContext.uiSchemaContext.creator;
414
+ return ("capturerVerbatim" in mediaMetadata)
415
+ ? Promise.resolve(Object.assign(Object.assign({}, mediaMetadata), { capturerVerbatim: [mediaMetadata.capturerVerbatim] }))
416
+ : MACode
417
+ ? this.apiClient.fetchCached(`/person/by-id/${MACode}`).then(({ fullName = MACode }) => (Object.assign(Object.assign({ capturerVerbatim: Array.isArray(fullName) ? fullName : [fullName] }, mediaMetadata), { intellectualOwner: fullName }))).catch(() => Promise.resolve(mediaMetadata))
418
+ : mediaMetadata;
419
+ };
420
+ this.getMaxFileSizeAsString = () => {
421
+ let maxSize = this.MAX_FILE_SIZE.toString().substring(0, this.MAX_FILE_SIZE.toString().length - 6);
422
+ return maxSize + " " + `${this.props.formContext.translations.Mb}`;
423
+ };
424
+ this.getAllowedMediaFormatsAsString = () => {
425
+ let formats = "";
426
+ for (let i = 0; i < this.ALLOWED_FILE_TYPES.length; i++) {
427
+ formats += this.ALLOWED_FILE_TYPES[i].split("/")[1];
428
+ if (i < this.ALLOWED_FILE_TYPES.length - 2) {
429
+ formats += ", ";
430
+ }
431
+ else if (i === this.ALLOWED_FILE_TYPES.length - 2) {
432
+ formats += ` ${this.props.formContext.translations.and} `;
433
+ }
434
+ }
435
+ return formats;
436
+ };
437
+ const [props] = args;
438
+ ["ALLOWED_FILE_TYPES",
439
+ "MAX_FILE_SIZE",
440
+ "KEY",
441
+ "ENDPOINT",
442
+ "GLYPH",
443
+ "renderMedia",
444
+ "renderLoadingMedia",
445
+ "onMediaClick",
446
+ "formatValue",
447
+ "TRANSLATION_TAKE_NEW",
448
+ "TRANSLATION_SELECT_FILE",
449
+ "TRANSLATION_NO_MEDIA",
450
+ "CONTAINER_CLASS"
451
+ ].forEach(prop => {
452
+ if (this[prop] === undefined) {
453
+ throw new Error(`${utils_1.getReactComponentName(ComposedComponent)} doesn't implement MediaArrayField ${prop}`);
454
+ }
455
+ });
456
+ const options = this.getOptions(props.uiSchema);
457
+ Object.keys(this.deprecatedOptions).forEach(deprecated => {
458
+ if (options[deprecated] !== undefined) {
459
+ console.warn(`laji-form warning: ${utils_1.getReactComponentName(ComposedComponent)} ui:option '${deprecated}' is deprecated. Use '${this.deprecatedOptions[deprecated]}' instead!`);
460
+ }
461
+ });
462
+ this.apiClient = props.formContext.apiClient;
463
+ this._context = Context_1.default(`${this.KEY}_ARRAY_FIELD`);
464
+ if (!this._context.metadatas)
465
+ this._context.metadatas = {};
466
+ if (!this._context.tmpMedias)
467
+ this._context.tmpMedias = {};
468
+ this.state = { tmpMedias: Object.keys(this._context.tmpMedias[this.getContainerId()] || {}).map(i => +i) };
469
+ const { addModal, autoOpenAddModal } = options;
470
+ if (addModal
471
+ && autoOpenAddModal
472
+ && (props.formData || []).length === 0
473
+ && !props.formContext.uiSchemaContext.isEdit) {
474
+ this.state.addModal = addModal; // eslint-disable-line react/no-direct-mutation-state
475
+ }
476
+ }
477
+ componentDidMount() {
478
+ this.mounted = true;
479
+ }
480
+ componentWillUnmount() {
481
+ this.mounted = false;
482
+ }
483
+ render() {
484
+ const { schema, uiSchema, idSchema, name, formContext, readonly, disabled } = this.props;
485
+ const { translations } = formContext;
486
+ const { description, addModal } = utils_1.getUiOptions(uiSchema);
487
+ const title = (schema.title === undefined) ? name : schema.title;
488
+ const TitleFieldTemplate = utils_3.getTemplate("TitleFieldTemplate", this.props.registry, utils_1.getUiOptions(this.props.uiSchema));
489
+ const { OverlayTrigger, Tooltip, Glyphicon } = this.context.theme;
490
+ const tooltip = (React.createElement(Tooltip, { id: `${this.props.idSchema.$id}-drop-zone-tooltip` },
491
+ React.createElement("span", null,
492
+ translations.DropOrSelectFiles,
493
+ ". "),
494
+ React.createElement("span", null,
495
+ translations.AllowedFileFormats,
496
+ " ",
497
+ this.getAllowedMediaFormatsAsString(),
498
+ " ",
499
+ translations.and,
500
+ " ",
501
+ translations.allowedFileSize,
502
+ " ",
503
+ this.getMaxFileSizeAsString(),
504
+ ".")));
505
+ const { dragging } = this.state;
506
+ const { Row, Col } = this.context.theme;
507
+ const { DescriptionFieldTemplate } = this.props.registry.templates;
508
+ const mediaCount = (this.props.formData || []).length + (this.state.tmpMedias || []).length;
509
+ const showAdd = utils_1.isNullOrUndefined(this.props.schema.maxItems) || mediaCount < this.props.schema.maxItems;
510
+ return (React.createElement(Row, null,
511
+ React.createElement(Col, { xs: 12 },
512
+ React.createElement(TitleFieldTemplate, { title: title, schema: schema, uiSchema: uiSchema, id: idSchema.$id, registry: this.props.registry }),
513
+ description !== undefined ? React.createElement(DescriptionFieldTemplate, { description: description, schema: schema, id: idSchema.$id, registry: this.props.registry }) : null,
514
+ React.createElement("div", { className: `laji-form-medias ${this.CONTAINER_CLASS}` },
515
+ this.renderMedias(),
516
+ this.renderLoadingMedias(),
517
+ showAdd && React.createElement(OverlayTrigger, { overlay: tooltip },
518
+ React.createElement(react_dropzone_1.default, { accept: this.ACCEPT_FILE_TYPES, onDragEnter: this.onDragEnter, onDragLeave: this.onDragLeave, onDrop: this.onDrop, disabled: readonly || disabled, noKeyboard: true }, ({ getRootProps, getInputProps }) => {
519
+ const _a = getRootProps(), { onClick: _onClick } = _a, rootProps = __rest(_a, ["onClick"]);
520
+ const onClick = addModal ? this.defaultOnClick : _onClick;
521
+ return (React.createElement("div", Object.assign({ className: utils_1.classNames("laji-form-drop-zone", dragging && "dragging", (readonly || disabled) && " disabled"), onClick: onClick, role: "button", tabIndex: 0 }, rootProps, { onKeyDown: this.onKeyDown, ref: this.addMediaContainerRef }),
522
+ React.createElement("input", Object.assign({}, getInputProps())),
523
+ React.createElement(Glyphicon, { glyph: this.GLYPH })));
524
+ })),
525
+ this.renderMetadataModal(),
526
+ this.renderMediaAddModal()))));
527
+ }
528
+ saveMedias(files) {
529
+ const containerId = this.getContainerId();
530
+ let tmpMedias;
531
+ const fail = (translationKey, additionalInfo = "") => {
532
+ const translation = (Array.isArray(translationKey) ? translationKey : [translationKey])
533
+ .map((key) => this.props.formContext.translations[key])
534
+ .join(". ");
535
+ throw `${translation} ${additionalInfo}`;
536
+ };
537
+ return this.processFiles(files).then(processedFiles => {
538
+ let invalidFile = (files.length <= 0);
539
+ let fileTooLarge = false;
540
+ let noValidData = true;
541
+ if (!this._context.tmpMedias[containerId]) {
542
+ this._context.tmpMedias[containerId] = {};
543
+ }
544
+ tmpMedias = processedFiles.map(f => {
545
+ mediaUuid++;
546
+ this._context.tmpMedias[containerId][mediaUuid] = f.dataURL;
547
+ return mediaUuid;
548
+ });
549
+ this.mounted && this.setState({ tmpMedias: [...(this.state.tmpMedias || []), ...tmpMedias] });
550
+ const formDataBody = files.reduce((body, file) => {
551
+ if (!this.ALLOWED_FILE_TYPES.includes(file.type)) {
552
+ invalidFile = true;
553
+ }
554
+ else if (file.size > this.MAX_FILE_SIZE) {
555
+ fileTooLarge = true;
556
+ }
557
+ else {
558
+ body.append("data", file);
559
+ noValidData = false;
560
+ }
561
+ return body;
562
+ }, new FormData());
563
+ if (noValidData && invalidFile) {
564
+ fail("AllowedFileFormats", this.getAllowedMediaFormatsAsString() + ".");
565
+ return;
566
+ }
567
+ else if (noValidData && fileTooLarge) {
568
+ fail("AllowedFileSize", this.getMaxFileSizeAsString() + ".");
569
+ return;
570
+ }
571
+ else {
572
+ return this.apiClient.fetchRaw(`/${this.ENDPOINT}`, undefined, {
573
+ method: "POST",
574
+ body: formDataBody
575
+ });
576
+ }
577
+ }).then(response => {
578
+ if (!response)
579
+ return;
580
+ if (response.status < 400) {
581
+ return response.json();
582
+ }
583
+ else if (response.status === 400) {
584
+ fail("InvalidFile");
585
+ }
586
+ else if (response.status === 503) {
587
+ fail("InsufficientSpace");
588
+ }
589
+ else {
590
+ fail(["SomethingWentWrong", "TryAgainLater"]);
591
+ }
592
+ }).then(response => {
593
+ if (!response)
594
+ return;
595
+ return this.getMetadataPromise().then(mediaMetadata => {
596
+ return Promise.all(response.map((item) => {
597
+ return this.apiClient.fetchRaw(`/${this.ENDPOINT}/${item.id}`, undefined, {
598
+ method: "POST",
599
+ headers: {
600
+ "accept": "application/json",
601
+ "content-type": "application/json"
602
+ },
603
+ body: JSON.stringify(mediaMetadata)
604
+ }).then(response => {
605
+ if (response.status < 400) {
606
+ return response.json();
607
+ }
608
+ });
609
+ }));
610
+ });
611
+ }).then(response => {
612
+ if (!response)
613
+ return;
614
+ const ids = response.map((item) => item ? item.id : undefined).filter(item => item !== undefined);
615
+ tmpMedias.forEach(id => {
616
+ delete this._context.tmpMedias[containerId][id];
617
+ });
618
+ this.mounted && this.setState({ tmpMedias: this.state.tmpMedias.filter(id => !tmpMedias.includes(id)) });
619
+ return ids;
620
+ }).catch((e) => {
621
+ if (tmpMedias) {
622
+ tmpMedias.forEach(id => {
623
+ delete this._context.tmpMedias[containerId][id];
624
+ });
625
+ this.mounted && this.setState({ tmpMedias: this.state.tmpMedias.filter(id => !tmpMedias.includes(id)) });
626
+ }
627
+ throw e;
628
+ });
629
+ }
630
+ };
631
+ MediaArrayField.contextType = ReactContext_1.default;
632
+ MediaArrayField.propTypes = {
633
+ uiSchema: PropTypes.shape({
634
+ "ui:options": PropTypes.shape({
635
+ titleClassName: PropTypes.string,
636
+ addModal: PropTypes.oneOfType([
637
+ PropTypes.bool,
638
+ PropTypes.shape({
639
+ labels: PropTypes.shape({
640
+ cancel: PropTypes.string
641
+ })
642
+ })
643
+ ]),
644
+ autoOpenAddModal: PropTypes.bool,
645
+ autoOpenMetadataModal: PropTypes.bool,
646
+ sideEffects: PropTypes.object,
647
+ exifParsers: PropTypes.arrayOf(PropTypes.object)
648
+ })
649
+ }),
650
+ schema: PropTypes.shape({
651
+ type: PropTypes.oneOf(["array"]),
652
+ items: PropTypes.shape({
653
+ type: PropTypes.oneOf(["string"]).isRequired
654
+ }).isRequired
655
+ }).isRequired,
656
+ formData: PropTypes.array
657
+ };
658
+ MediaArrayField.displayName = utils_1.getReactComponentName(ComposedComponent);
659
+ MediaArrayField = __decorate([
660
+ BaseComponent_1.default
661
+ ], MediaArrayField);
662
+ return MediaArrayField;
663
+ }
664
+ exports.MediaArrayField = MediaArrayField;
665
+ class Thumbnail extends React.PureComponent {
666
+ constructor(props) {
667
+ super(props);
668
+ this.updateURL = ({ id, apiClient, apiEndpoint = "images" }) => {
669
+ if (!id)
670
+ return;
671
+ apiClient.fetchCached(`/${apiEndpoint}/${id}`, undefined, { failSilently: true }).then((response) => {
672
+ if (!this.mounted)
673
+ return;
674
+ this.setState({ url: response.squareThumbnailURL });
675
+ });
676
+ };
677
+ this.state = {};
678
+ this.updateURL(props);
679
+ }
680
+ componentDidMount() {
681
+ this.mounted = true;
682
+ }
683
+ componentWillUnmount() {
684
+ this.mounted = false;
685
+ }
686
+ UNSAFE_componentWillReceiveProps(props) {
687
+ this.updateURL(props);
688
+ }
689
+ render() {
690
+ const url = this.state.url || this.props.dataURL;
691
+ const img = url ? React.createElement("img", { src: url }) : null;
692
+ return (!url || this.props.loading)
693
+ ? React.createElement("div", { className: "media-loading" },
694
+ img,
695
+ React.createElement(Spinner, null))
696
+ : img;
697
+ }
698
+ }
699
+ exports.Thumbnail = Thumbnail;