@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,440 @@
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
+ const React = require("react");
21
+ const react_dom_1 = require("react-dom");
22
+ const PropTypes = require("prop-types");
23
+ const BaseComponent_1 = require("../BaseComponent");
24
+ const components_1 = require("../components");
25
+ const Context_1 = require("../../Context");
26
+ const utils_1 = require("../../utils");
27
+ const MapArrayField_1 = require("./MapArrayField");
28
+ const ReactContext_1 = require("../../ReactContext");
29
+ let LocationChooserField = class LocationChooserField extends React.Component {
30
+ getStateFromProps(props) {
31
+ let uiSchema = utils_1.getInnerUiSchema(props.uiSchema);
32
+ uiSchema = Object.assign(Object.assign({}, uiSchema), { "ui:buttons": [
33
+ ...(uiSchema["ui:buttons"] || []),
34
+ React.createElement(LocationButton, { key: `$${this.props.idSchema.$id}-location`, that: this })
35
+ ] });
36
+ return { uiSchema };
37
+ }
38
+ render() {
39
+ const SchemaField = this.props.registry.fields.SchemaField;
40
+ return React.createElement(SchemaField, Object.assign({}, this.props, this.state));
41
+ }
42
+ };
43
+ LocationChooserField.propTypes = {
44
+ uiSchema: PropTypes.shape({
45
+ "ui:options": PropTypes.shape({
46
+ uiSchema: PropTypes.object,
47
+ taxonField: PropTypes.string,
48
+ geometryField: PropTypes.string,
49
+ strategy: PropTypes.oneOf(["unit", "lolife", "lolifeUnit"]),
50
+ mapOptions: PropTypes.object,
51
+ maxShapes: PropTypes.number,
52
+ preselectMarker: PropTypes.bool,
53
+ color: PropTypes.string
54
+ })
55
+ }).isRequired,
56
+ schema: PropTypes.shape({
57
+ type: PropTypes.oneOf(["object"])
58
+ }).isRequired,
59
+ formData: PropTypes.object.isRequired
60
+ };
61
+ LocationChooserField = __decorate([
62
+ BaseComponent_1.default
63
+ ], LocationChooserField);
64
+ exports.default = LocationChooserField;
65
+ class LocationButton extends React.Component {
66
+ constructor(props) {
67
+ super(props);
68
+ this.getIdx = () => {
69
+ const { that } = this.props;
70
+ const { $id } = that.props.idSchema;
71
+ const splitted = $id.split("_");
72
+ return parseInt(splitted[splitted.length - 1]);
73
+ };
74
+ this.getGeometryField = () => {
75
+ const { that } = this.props;
76
+ const { geometryField = "geometry" } = utils_1.getUiOptions(that.props.uiSchema);
77
+ return geometryField;
78
+ };
79
+ this.hasCoordinates = () => {
80
+ return MapArrayField_1.parseGeometries(this.getGeometry()).length;
81
+ };
82
+ this.getGeometry = () => {
83
+ const geometryField = this.getGeometryField();
84
+ return utils_1.parseJSONPointer(this.props.that.props.formData, geometryField);
85
+ };
86
+ this.onMouseEnter = () => {
87
+ const { that } = this.props;
88
+ const idx = this.getIdx();
89
+ this._hovered = true;
90
+ if (typeof idx === "number") {
91
+ that.props.formContext.services.customEvents.send(that.props.idSchema.$id, "startHighlight", { id: utils_1.getUUID(that.props.formData), idx });
92
+ }
93
+ };
94
+ this.onMouseLeave = () => {
95
+ const { that } = this.props;
96
+ const idx = this.getIdx();
97
+ this._hovered = false;
98
+ if (typeof idx === "number") {
99
+ that.props.formContext.services.customEvents.send(that.props.idSchema.$id, "endHighlight", { id: utils_1.getUUID(that.props.formData), idx });
100
+ }
101
+ };
102
+ this.getUnitDrawFeatureStyle = () => ({ color: "#55AEFA" });
103
+ this.getDataFeatureStyle = () => ({ color: "#aaaaaa", opacity: 0.7 });
104
+ this.getData = () => {
105
+ const { that } = this.props;
106
+ const { strategy = "unit" } = utils_1.getUiOptions(that.props.uiSchema);
107
+ switch (strategy) {
108
+ case "unit":
109
+ return this.getUnitData();
110
+ case "lolifeUnit":
111
+ case "lolife":
112
+ return this.getLolifeData();
113
+ }
114
+ };
115
+ this.getUnitData = () => {
116
+ const { that } = this.props;
117
+ const mapContext = Context_1.default(`${that.props.formContext.contextId}_MAP`);
118
+ const { map } = mapContext;
119
+ const emptyFeatureCollection = { featureCollection: { type: "FeatureCollection", features: [] } };
120
+ const gatheringData = map ? map.getDraw() : emptyFeatureCollection;
121
+ const [unitGeometriesData, ...unitGeometryCollectionsData] = map
122
+ ? map.data.filter(i => i) || [emptyFeatureCollection]
123
+ : [emptyFeatureCollection];
124
+ const idx = this.getIdx();
125
+ const geometry = this.getGeometry();
126
+ const draw = geometry && geometry.type
127
+ ? {
128
+ featureCollection: { type: "FeatureCollection", features: [{ type: "Feature", geometry }] },
129
+ getFeatureStyle: this.getUnitDrawFeatureStyle,
130
+ }
131
+ : undefined;
132
+ if (unitGeometriesData && draw)
133
+ draw.getFeatureStyle = unitGeometriesData.getFeatureStyle;
134
+ return [
135
+ draw,
136
+ [
137
+ {
138
+ featureCollection: gatheringData.featureCollection,
139
+ getFeatureStyle: this.getDataFeatureStyle
140
+ },
141
+ {
142
+ featureCollection: {
143
+ type: "FeatureCollection",
144
+ features: unitGeometriesData.featureCollection.features.filter(feature => feature.properties.idx !== idx)
145
+ },
146
+ getFeatureStyle: this.getDataFeatureStyle
147
+ },
148
+ ...unitGeometryCollectionsData.map(data => ({
149
+ featureCollection: {
150
+ type: "FeatureCollection",
151
+ features: data.featureCollection.features.filter(feature => feature.properties.idx !== idx)
152
+ },
153
+ getFeatureStyle: this.getDataFeatureStyle
154
+ }))
155
+ ]
156
+ ];
157
+ };
158
+ this.getLolifeData = () => {
159
+ const { that } = this.props;
160
+ const mapContext = Context_1.default(`${that.props.formContext.contextId}_MAP`);
161
+ const { map } = mapContext;
162
+ const { strategy = "unit" } = utils_1.getUiOptions(that.props.uiSchema);
163
+ let draw;
164
+ if (strategy === "lolife") {
165
+ draw = map.getDraw();
166
+ }
167
+ const id = utils_1.getUUID(that.props.formData);
168
+ let data = map.data.filter((item) => {
169
+ const isCurrent = item.featureCollection.features[0].properties.id === id;
170
+ if (strategy === "lolifeUnit" && isCurrent) {
171
+ draw = Object.assign(Object.assign({}, item), { idx: map.drawIdx, getPopup: undefined, on: undefined, getFeatureStyle: this.getFeatureStyleWithHighlight(item.getFeatureStyle), getDraftStyle: () => this.getFeatureStyleWithHighlight(item.getFeatureStyle)({ feature: { properties: { id } } }, !!"higlight") });
172
+ }
173
+ return !isCurrent;
174
+ }).map(item => (Object.assign(Object.assign({}, item), { getPopup: undefined, on: undefined, getFeatureStyle: this.getFeatureStyleWithLowerOpacity(item.getFeatureStyle) })));
175
+ if (strategy === "lolifeUnit") {
176
+ data.push(map.getDraw());
177
+ }
178
+ return [
179
+ draw,
180
+ data
181
+ ];
182
+ };
183
+ this.onClick = () => {
184
+ const { that } = this.props;
185
+ const { disabled, readonly } = that.props;
186
+ const mapContext = Context_1.default(`${that.props.formContext.contextId}_MAP`);
187
+ const { map } = mapContext;
188
+ this.triggerLayer = undefined;
189
+ let [draw, data] = this.getData();
190
+ data = data.map(d => (Object.assign(Object.assign({}, d), { editable: false })));
191
+ const _a = map ? map.getOptions() : { mapOptions: {} }, { rootElem, customControls, zoom, center } = _a, mapOptions = __rest(_a, ["rootElem", "customControls", "zoom", "center"]); // eslint-disable-line @typescript-eslint/no-unused-vars
192
+ const { mapOptions: { marker = true, polyline = false, rectangle = false, polygon = false, circle = false } = {} } = utils_1.getUiOptions(that.props.uiSchema);
193
+ const modalMap = Object.assign(Object.assign({}, mapOptions), { data, draw: Object.assign(Object.assign({}, draw), { marker,
194
+ polyline,
195
+ rectangle,
196
+ polygon,
197
+ circle, onChange: this.onChange, editable: !readonly && !disabled }), controls: Object.assign(Object.assign({}, mapOptions.controls), { draw: Object.assign(Object.assign({}, ((mapOptions.controls || {}).draw || {})), { clear: true, delete: true }) }), fullscreenable: true, zoomToData: draw ? { draw: true } : true, clickBeforeZoomAndPan: false, onComponentDidMount: this.onMapMounted });
198
+ if (center) {
199
+ modalMap.center = center;
200
+ }
201
+ if (zoom) {
202
+ modalMap.zoom = zoom;
203
+ }
204
+ this.setState({
205
+ modalMap
206
+ });
207
+ };
208
+ this.getGrey = () => ({ opacity: 0.6, color: "#888888" });
209
+ this.getFeatureStyle = () => ({ color: "#75CEFA" });
210
+ this.onChange = (events) => {
211
+ const { that } = this.props;
212
+ const { maxShapes = 1 } = utils_1.getUiOptions(that.props.uiSchema);
213
+ const _that = this;
214
+ function close() {
215
+ _that.triggerLayer && _that.triggerLayer.disable();
216
+ _that.onHide();
217
+ }
218
+ const geometryField = this.getGeometryField();
219
+ for (let event of events) {
220
+ const { type } = event;
221
+ const geometryRef = utils_1.parseJSONPointer(that.props.formData, geometryField);
222
+ switch (type) {
223
+ case "create": {
224
+ if (geometryRef && geometryRef.type && (maxShapes > 1 || maxShapes === -1)) {
225
+ if (geometryRef.geometries && maxShapes !== -1 && geometryRef.geometries.length >= maxShapes) {
226
+ this.setState({ shapeAlert: { label: "tooManyShapes", max: maxShapes } });
227
+ return;
228
+ }
229
+ const geometries = geometryRef && geometryRef.geometries
230
+ ? geometryRef.geometries
231
+ : geometryRef && geometryRef.type
232
+ ? [geometryRef]
233
+ : [];
234
+ that.props.onChange(utils_1.updateFormDataWithJSONPointer(that.props, { type: "GeometryCollection", geometries: [...geometries, event.feature.geometry] }, geometryField));
235
+ }
236
+ else {
237
+ that.props.onChange(utils_1.updateFormDataWithJSONPointer(that.props, event.feature.geometry, geometryField));
238
+ }
239
+ // TODO LajiMap doesn't send a sequence of events containing multiple events if
240
+ // it sends a create event, but this isn't necessarily true in the future and
241
+ // closing here wouldn't be right.
242
+ close();
243
+ break;
244
+ }
245
+ case "delete": {
246
+ if (!geometryRef || !geometryRef.type) {
247
+ break;
248
+ }
249
+ that.props.onChange(utils_1.updateFormDataWithJSONPointer(that.props, utils_1.getDefaultFormState(utils_1.parseSchemaFromFormDataPointer(that.props.schema, geometryField)), geometryField));
250
+ break;
251
+ }
252
+ case "edit": {
253
+ if (!geometryRef || !geometryRef.type) {
254
+ break;
255
+ }
256
+ if (geometryRef.type === "GeometryCollection" && geometryRef.geometries) {
257
+ const geometry = Object.keys(event.features).reduce((geometry, idx) => {
258
+ const feature = event.features[idx];
259
+ geometry = Object.assign(Object.assign({}, geometry), { geometries: Object.assign(Object.assign({}, geometry.geometries), { [idx]: feature.geometry }) });
260
+ return geometry;
261
+ }, utils_1.parseJSONPointer(that.props.formData, geometryField));
262
+ that.props.onChange(utils_1.updateFormDataWithJSONPointer(that.props, geometry, geometryField));
263
+ }
264
+ else if (geometryRef.type) {
265
+ that.props.onChange(utils_1.updateFormDataWithJSONPointer(that.props, event.features[0].geometry, geometryField));
266
+ }
267
+ }
268
+ }
269
+ if (geometryRef
270
+ && geometryRef.geometries
271
+ && geometryRef.geometries.length <= maxShapes
272
+ && type !== "edit") {
273
+ this.setState({ shapeAlert: undefined });
274
+ }
275
+ }
276
+ };
277
+ this.onMapMounted = (map) => {
278
+ const { that } = this.props;
279
+ const { disabled, readonly } = that.props;
280
+ const { preselectMarker = true } = utils_1.getUiOptions(that.props.uiSchema);
281
+ map.resetDrawUndoStack();
282
+ if (!disabled && !readonly && preselectMarker) {
283
+ this.triggerLayer = map.triggerDrawing("marker");
284
+ }
285
+ };
286
+ this.getMiniMapData = () => {
287
+ const { that } = this.props;
288
+ const { strategy = "unit" } = utils_1.getUiOptions(that.props.uiSchema);
289
+ switch (strategy) {
290
+ case "unit":
291
+ return this.getUnitMiniMapData();
292
+ case "lolifeUnit":
293
+ return this.getLolifeUnitMiniMapData();
294
+ case "lolife":
295
+ return this.getLolifeMiniMapData();
296
+ }
297
+ };
298
+ this.getUnitMiniMapData = () => {
299
+ const { that } = this.props;
300
+ const mapContext = Context_1.default(`${that.props.formContext.contextId}_MAP`);
301
+ const { map } = mapContext;
302
+ const geometry = this.getGeometry();
303
+ const data = [
304
+ ...(map && map.getDraw() ? [Object.assign(Object.assign({}, map.getDraw()), { getFeatureStyle: this.getGrey })] : []),
305
+ ...(map && map.data && map.data[0] ? [Object.assign(Object.assign({}, map.data[0]), { getFeatureStyle: this.getGrey })] : []),
306
+ {
307
+ geoData: geometry,
308
+ getFeatureStyle: this.getFeatureStyle
309
+ }
310
+ ];
311
+ return [
312
+ data,
313
+ { dataIdxs: [data.length - 1] }
314
+ ];
315
+ };
316
+ this.getLolifeMiniMapData = () => {
317
+ const { that } = this.props;
318
+ const mapContext = Context_1.default(`${that.props.formContext.contextId}_MAP`);
319
+ const { map } = mapContext;
320
+ const draw = map.getDraw();
321
+ return [
322
+ [
323
+ draw,
324
+ ...map.data.map((item) => {
325
+ return Object.assign(Object.assign({}, item), { getPopup: undefined, on: undefined, editable: false, getFeatureStyle: item.getFeatureStyle });
326
+ })
327
+ ],
328
+ { dataIdxs: [draw.idx || 0] }
329
+ ];
330
+ };
331
+ this.getLolifeUnitMiniMapData = () => {
332
+ const { that } = this.props;
333
+ const mapContext = Context_1.default(`${that.props.formContext.contextId}_MAP`);
334
+ const { map } = mapContext;
335
+ const id = utils_1.getUUID(that.props.formData);
336
+ return [
337
+ [
338
+ ...map.data.map((item) => (Object.assign(Object.assign({}, item), { getPopup: undefined, on: undefined, editable: false, getFeatureStyle: item.getFeatureStyle
339
+ ? item.featureCollection.features[0].properties.id === id
340
+ ? this.getFeatureStyleWithHighlight(item.getFeatureStyle)
341
+ : this.getFeatureStyleWithLowerOpacity(item.getFeatureStyle)
342
+ : undefined }))),
343
+ map.getDraw()
344
+ ],
345
+ { dataIdxs: [map.data.findIndex(d => d.featureCollection.features[0].properties.id === id)] }
346
+ ];
347
+ };
348
+ this.getFeatureStyleWithLowerOpacity = getFeatureStyle => (...params) => {
349
+ const style = getFeatureStyle(...params);
350
+ return MapArrayField_1.getFeatureStyleWithLowerOpacity(style);
351
+ };
352
+ this.getFeatureStyleWithHighlight = getFeatureStyle => (...params) => {
353
+ const style = getFeatureStyle(...params);
354
+ return MapArrayField_1.getFeatureStyleWithHighlight(style);
355
+ };
356
+ this.onEntered = () => {
357
+ const { that } = this.props;
358
+ const mapContext = Context_1.default(`${that.props.formContext.contextId}_MAP`);
359
+ if (!mapContext) {
360
+ return;
361
+ }
362
+ const { map } = mapContext;
363
+ let mapOptions = {};
364
+ if (map) {
365
+ const _a = map.getOptions(), { rootElem, zoom, center } = _a, _mapOptions = __rest(_a, ["rootElem", "zoom", "center"]); //eslint-disable-line @typescript-eslint/no-unused-vars
366
+ mapOptions = _mapOptions;
367
+ }
368
+ const [data, zoomToData] = this.getMiniMapData();
369
+ this.setState({
370
+ miniMap: Object.assign(Object.assign({}, mapOptions), { draw: false, controls: false, customControls: undefined, zoomToData,
371
+ data, clickBeforeZoomAndPan: false })
372
+ });
373
+ };
374
+ this.onHide = () => {
375
+ this.setState({ modalMap: undefined });
376
+ };
377
+ this.onModalMapKeyDown = (e) => {
378
+ if (e.key === "Escape" && !this.modalMapRef.map.keyHandler(e.nativeEvent)) {
379
+ this.onHide();
380
+ }
381
+ };
382
+ this.setMapRef = (elem) => {
383
+ this.modalMapRef = elem;
384
+ };
385
+ this.setMiniMapRef = (elem) => {
386
+ this.miniMapRef = elem;
387
+ };
388
+ this.setButtonRef = (elem) => {
389
+ this.buttonRef = elem;
390
+ };
391
+ this.getButtonElem = () => react_dom_1.findDOMNode(this.buttonRef);
392
+ this.renderButton = () => {
393
+ const { that, glyph = "map-marker", label } = this.props;
394
+ const id = that.props.idSchema.$id;
395
+ const { color } = utils_1.getUiOptions(that.props.uiSchema);
396
+ const hasCoordinates = this.hasCoordinates();
397
+ const geometryField = this.getGeometryField();
398
+ const hasErrors = utils_1.parseJSONPointer(utils_1.filteredErrors(that.props.errorSchema), geometryField);
399
+ const variant = hasErrors
400
+ ? "danger"
401
+ : undefined;
402
+ const button = React.createElement(components_1.GlyphButton, { key: `${that.props.idSchema.$id}-location`, id: `${that.props.idSchema.$id}-location`, variant: variant, active: !!hasCoordinates, onMouseEnter: this.onMouseEnter, onMouseLeave: this.onMouseLeave, glyph: glyph, onClick: this.onClick, style: hasCoordinates && !hasErrors && color ? { backgroundColor: color } : undefined, ref: this.setButtonRef });
403
+ const { Overlay, Popover, Tooltip } = this.context.theme;
404
+ if (hasErrors) {
405
+ return (React.createElement(React.Fragment, null,
406
+ button,
407
+ React.createElement(Overlay, { show: true, container: this, target: this.getButtonElem, placement: "left" },
408
+ React.createElement(Tooltip, { id: `laji-form-error-container-${id}_${utils_1.JSONPointerToId(geometryField)}`, className: "location-chooser-errors" },
409
+ React.createElement("ul", null, hasErrors.__errors.map((e, i) => React.createElement("li", { key: i }, utils_1.formatErrorMessage(e))))))));
410
+ }
411
+ else {
412
+ const { translations } = that.props.formContext;
413
+ const overlay = hasCoordinates ? (React.createElement(Popover, { id: `${id}-location-peeker`, title: `${translations.ChooseLocation} (${translations.below} ${translations.currentLocation})` },
414
+ React.createElement(MapArrayField_1.Map, Object.assign({}, this.state.miniMap, { hidden: !this.state.miniMap || this.state.modalMap, style: { width: 200, height: 200 }, singleton: true, formContext: that.props.formContext, bodyAsDialogRoot: false, ref: this.setMiniMapRef })))) : (React.createElement(Tooltip, { id: `${id}-location-peeker` }, label || that.props.formContext.translations.ChooseLocation));
415
+ return (React.createElement(components_1.OverlayTrigger, { key: `${id}-set-coordinates-${glyph}`, overlay: overlay, placement: "left", hoverable: true, formContext: that.props.formContext, onEntered: hasCoordinates ? this.onEntered : undefined }, button));
416
+ }
417
+ };
418
+ this.state = {};
419
+ }
420
+ componentWillUnmount() {
421
+ this._hovered && this.onMouseLeave();
422
+ }
423
+ render() {
424
+ const { that } = this.props;
425
+ const { shapeAlert } = this.state;
426
+ const { taxonField, title } = utils_1.getUiOptions(that.props.uiSchema);
427
+ const { translations } = that.props.formContext;
428
+ const { Modal, Alert } = this.context.theme;
429
+ return (React.createElement(React.Fragment, null,
430
+ this.renderButton(),
431
+ this.state.modalMap &&
432
+ React.createElement(Modal, { key: "map-modal", show: true, dialogClassName: "laji-form map-dialog", onHide: this.onHide, keyboard: false, onKeyDown: this.onModalMapKeyDown },
433
+ React.createElement(Modal.Header, { closeButton: true },
434
+ React.createElement(Modal.Title, null, title || `${translations.SetLocationToUnit}${that.props.formData[taxonField] ? ` (${that.props.formData[taxonField]})` : ""}`)),
435
+ React.createElement(Modal.Body, null,
436
+ shapeAlert && React.createElement(Alert, { variant: "danger" }, translations[shapeAlert.label] + shapeAlert.max),
437
+ React.createElement(MapArrayField_1.Map, Object.assign({}, this.state.modalMap, { singleton: true, formContext: that.props.formContext, ref: this.setMapRef, bodyAsDialogRoot: false }))))));
438
+ }
439
+ }
440
+ LocationButton.contextType = ReactContext_1.default;
@@ -0,0 +1,78 @@
1
+ export function parseGeometries(geometry: any): any;
2
+ export default class MapArrayField extends React.Component<any, any, any> {
3
+ static propTypes: {
4
+ uiSchema: PropTypes.Requireable<PropTypes.InferProps<{
5
+ "ui:options": PropTypes.Validator<PropTypes.InferProps<{
6
+ geometryField: PropTypes.Requireable<string>;
7
+ geometryMapper: PropTypes.Requireable<string>;
8
+ topOffset: PropTypes.Requireable<number>;
9
+ bottomOffset: PropTypes.Requireable<number>;
10
+ popupFields: PropTypes.Requireable<(object | null | undefined)[]>;
11
+ computeAreaField: PropTypes.Requireable<string>;
12
+ areaInHectares: PropTypes.Requireable<boolean>;
13
+ mapSizes: PropTypes.Requireable<PropTypes.InferProps<{
14
+ lg: PropTypes.Requireable<number>;
15
+ md: PropTypes.Requireable<number>;
16
+ sm: PropTypes.Requireable<number>;
17
+ xs: PropTypes.Requireable<number>;
18
+ }>>;
19
+ data: PropTypes.Requireable<(PropTypes.InferProps<{
20
+ geometryField: PropTypes.Validator<string>;
21
+ }> | null | undefined)[]>;
22
+ help: PropTypes.Requireable<string>;
23
+ }>>;
24
+ }>>;
25
+ schema: PropTypes.Validator<PropTypes.InferProps<{
26
+ type: PropTypes.Requireable<string>;
27
+ }>>;
28
+ formData: PropTypes.Requireable<object>;
29
+ };
30
+ constructor(props: any);
31
+ constructor(props: any, context: any);
32
+ }
33
+ export class MapComponent extends React.Component<any, any, any> {
34
+ static contextType: React.Context<import("../../ReactContext").ContextProps>;
35
+ constructor(props: any);
36
+ mainContext: Record<string, unknown>;
37
+ _context: Record<string, unknown>;
38
+ tileLayerChange: ({ tileLayers }: {
39
+ tileLayers: any;
40
+ }) => void;
41
+ overlaysChange: ({ overlayNames }: {
42
+ overlayNames: any;
43
+ }) => void;
44
+ tileLayerOpacityChangeEnd: ({ tileLayerOpacity }: {
45
+ tileLayerOpacity: any;
46
+ }) => void;
47
+ locateToggle: ({ locate }: {
48
+ locate: any;
49
+ }) => void;
50
+ map: any;
51
+ _callback: any;
52
+ grabFocus: () => void;
53
+ releaseFocus: () => void;
54
+ showPanel: (options: any) => void;
55
+ hidePanel: () => void;
56
+ showHelp: () => void;
57
+ hideHelp: () => void;
58
+ setMapState: (options: any, callback: any) => void;
59
+ setOnUpdateMap: (fn: any) => void;
60
+ _permaCallback: any;
61
+ }
62
+ export class Map extends React.Component<any, any, any> {
63
+ static defaultProps: {
64
+ tileLayerName: string;
65
+ availableTileLayerNamesBlacklist: string[];
66
+ };
67
+ constructor(props: any);
68
+ mounted: boolean | undefined;
69
+ getMapOptions: (props: any) => any;
70
+ getEnhancedMapOptions: (props: any) => any;
71
+ setMapOptions: (prevOptions: any, options: any) => void;
72
+ initializeMap: (props: any) => void;
73
+ map: any;
74
+ }
75
+ export function getFeatureStyleWithLowerOpacity(style: any): any;
76
+ export function getFeatureStyleWithHighlight(style: any): any;
77
+ import * as React from "react";
78
+ import * as PropTypes from "prop-types";