@luomus/laji-form 15.1.0 → 15.1.2

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 (248) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/dist/laji-form.js +1 -1
  3. package/jsonconfig.json +26 -0
  4. package/migrate.sh +0 -1
  5. package/package.json +8 -8
  6. package/test-export/test-utils.d.ts +100 -54
  7. package/test-export/test-utils.js +102 -84
  8. package/xsel -b +9 -0
  9. package/cypress/fixtures/example.json +0 -5
  10. package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and closes suggestion list (failed).png +0 -0
  11. package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and is marked as suggested (failed).png +0 -0
  12. package/lib/ApiClient.d.ts +0 -46
  13. package/lib/ApiClient.js +0 -93
  14. package/lib/Context.d.ts +0 -8
  15. package/lib/Context.js +0 -18
  16. package/lib/ReactContext.d.ts +0 -7
  17. package/lib/ReactContext.js +0 -5
  18. package/lib/components/BaseComponent.d.ts +0 -9
  19. package/lib/components/BaseComponent.js +0 -29
  20. package/lib/components/LajiForm.d.ts +0 -221
  21. package/lib/components/LajiForm.js +0 -615
  22. package/lib/components/VirtualSchemaField.d.ts +0 -42
  23. package/lib/components/VirtualSchemaField.js +0 -74
  24. package/lib/components/components.d.ts +0 -119
  25. package/lib/components/components.js +0 -606
  26. package/lib/components/fields/AnnotationField.d.ts +0 -34
  27. package/lib/components/fields/AnnotationField.js +0 -242
  28. package/lib/components/fields/AnyToBooleanField.d.ts +0 -18
  29. package/lib/components/fields/AnyToBooleanField.js +0 -20
  30. package/lib/components/fields/ArrayBulkField.d.ts +0 -23
  31. package/lib/components/fields/ArrayBulkField.js +0 -82
  32. package/lib/components/fields/ArrayCombinerField.d.ts +0 -36
  33. package/lib/components/fields/ArrayCombinerField.js +0 -138
  34. package/lib/components/fields/ArrayField.d.ts +0 -39
  35. package/lib/components/fields/ArrayField.js +0 -148
  36. package/lib/components/fields/AudioArrayField.d.ts +0 -22
  37. package/lib/components/fields/AudioArrayField.js +0 -100
  38. package/lib/components/fields/AutoArrayField.d.ts +0 -24
  39. package/lib/components/fields/AutoArrayField.js +0 -56
  40. package/lib/components/fields/AutosuggestField.d.ts +0 -69
  41. package/lib/components/fields/AutosuggestField.js +0 -299
  42. package/lib/components/fields/CombinedValueDisplayField.d.ts +0 -41
  43. package/lib/components/fields/CombinedValueDisplayField.js +0 -100
  44. package/lib/components/fields/ConditionalOnChangeField.d.ts +0 -42
  45. package/lib/components/fields/ConditionalOnChangeField.js +0 -107
  46. package/lib/components/fields/ConditionalUiSchemaField.d.ts +0 -123
  47. package/lib/components/fields/ConditionalUiSchemaField.js +0 -143
  48. package/lib/components/fields/ContextInjectionField.d.ts +0 -24
  49. package/lib/components/fields/ContextInjectionField.js +0 -68
  50. package/lib/components/fields/DataLeakerField.d.ts +0 -40
  51. package/lib/components/fields/DataLeakerField.js +0 -68
  52. package/lib/components/fields/DefaultValueArrayField.d.ts +0 -34
  53. package/lib/components/fields/DefaultValueArrayField.js +0 -59
  54. package/lib/components/fields/DependentBooleanField.d.ts +0 -38
  55. package/lib/components/fields/DependentBooleanField.js +0 -87
  56. package/lib/components/fields/DependentDisableField.d.ts +0 -35
  57. package/lib/components/fields/DependentDisableField.js +0 -71
  58. package/lib/components/fields/EnumRangeArrayField.d.ts +0 -27
  59. package/lib/components/fields/EnumRangeArrayField.js +0 -115
  60. package/lib/components/fields/ExtraLabelRowField.d.ts +0 -38
  61. package/lib/components/fields/ExtraLabelRowField.js +0 -100
  62. package/lib/components/fields/FakePropertyField.d.ts +0 -18
  63. package/lib/components/fields/FakePropertyField.js +0 -48
  64. package/lib/components/fields/FilterArrayField.d.ts +0 -73
  65. package/lib/components/fields/FilterArrayField.js +0 -121
  66. package/lib/components/fields/FlatField.d.ts +0 -29
  67. package/lib/components/fields/FlatField.js +0 -171
  68. package/lib/components/fields/GeocoderField.d.ts +0 -47
  69. package/lib/components/fields/GeocoderField.js +0 -372
  70. package/lib/components/fields/GridLayoutField.d.ts +0 -18
  71. package/lib/components/fields/GridLayoutField.js +0 -32
  72. package/lib/components/fields/HiddenField.d.ts +0 -10
  73. package/lib/components/fields/HiddenField.js +0 -11
  74. package/lib/components/fields/ImageArrayField.d.ts +0 -172
  75. package/lib/components/fields/ImageArrayField.js +0 -697
  76. package/lib/components/fields/ImageDisplayField.d.ts +0 -18
  77. package/lib/components/fields/ImageDisplayField.js +0 -44
  78. package/lib/components/fields/InitiallyHiddenField.d.ts +0 -21
  79. package/lib/components/fields/InitiallyHiddenField.js +0 -58
  80. package/lib/components/fields/InjectDefaultValueField.d.ts +0 -37
  81. package/lib/components/fields/InjectDefaultValueField.js +0 -68
  82. package/lib/components/fields/InjectField.d.ts +0 -46
  83. package/lib/components/fields/InjectField.js +0 -88
  84. package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +0 -25
  85. package/lib/components/fields/InputWithDefaultValueButtonField.js +0 -61
  86. package/lib/components/fields/LocalityField.d.ts +0 -22
  87. package/lib/components/fields/LocalityField.js +0 -94
  88. package/lib/components/fields/LocationChooserField.d.ts +0 -27
  89. package/lib/components/fields/LocationChooserField.js +0 -440
  90. package/lib/components/fields/MapArrayField.d.ts +0 -78
  91. package/lib/components/fields/MapArrayField.js +0 -1783
  92. package/lib/components/fields/MapField.d.ts +0 -48
  93. package/lib/components/fields/MapField.js +0 -434
  94. package/lib/components/fields/MultiAnyToBooleanField.d.ts +0 -25
  95. package/lib/components/fields/MultiAnyToBooleanField.js +0 -100
  96. package/lib/components/fields/MultiArrayField.d.ts +0 -53
  97. package/lib/components/fields/MultiArrayField.js +0 -224
  98. package/lib/components/fields/MultiLanguageField.d.ts +0 -13
  99. package/lib/components/fields/MultiLanguageField.js +0 -52
  100. package/lib/components/fields/MultiTagArrayField.d.ts +0 -36
  101. package/lib/components/fields/MultiTagArrayField.js +0 -142
  102. package/lib/components/fields/NamedPlaceChooserField.d.ts +0 -29
  103. package/lib/components/fields/NamedPlaceChooserField.js +0 -380
  104. package/lib/components/fields/NamedPlaceSaverField.d.ts +0 -29
  105. package/lib/components/fields/NamedPlaceSaverField.js +0 -237
  106. package/lib/components/fields/NestField.d.ts +0 -148
  107. package/lib/components/fields/NestField.js +0 -289
  108. package/lib/components/fields/ObjectField.d.ts +0 -2
  109. package/lib/components/fields/ObjectField.js +0 -119
  110. package/lib/components/fields/PdfArrayField.d.ts +0 -21
  111. package/lib/components/fields/PdfArrayField.js +0 -40
  112. package/lib/components/fields/PrefillingArrayField.d.ts +0 -22
  113. package/lib/components/fields/PrefillingArrayField.js +0 -65
  114. package/lib/components/fields/SchemaField.d.ts +0 -7
  115. package/lib/components/fields/SchemaField.js +0 -109
  116. package/lib/components/fields/ScopeField.d.ts +0 -85
  117. package/lib/components/fields/ScopeField.js +0 -521
  118. package/lib/components/fields/SectionArrayField.d.ts +0 -38
  119. package/lib/components/fields/SectionArrayField.js +0 -618
  120. package/lib/components/fields/SelectTreeField.d.ts +0 -39
  121. package/lib/components/fields/SelectTreeField.js +0 -143
  122. package/lib/components/fields/SingleActiveArrayField.d.ts +0 -49
  123. package/lib/components/fields/SingleActiveArrayField.js +0 -974
  124. package/lib/components/fields/SingleItemArrayField.d.ts +0 -15
  125. package/lib/components/fields/SingleItemArrayField.js +0 -60
  126. package/lib/components/fields/SortArrayField.d.ts +0 -73
  127. package/lib/components/fields/SortArrayField.js +0 -351
  128. package/lib/components/fields/SplitField.d.ts +0 -28
  129. package/lib/components/fields/SplitField.js +0 -65
  130. package/lib/components/fields/StringToArrayField.d.ts +0 -24
  131. package/lib/components/fields/StringToArrayField.js +0 -48
  132. package/lib/components/fields/SumField.d.ts +0 -35
  133. package/lib/components/fields/SumField.js +0 -83
  134. package/lib/components/fields/TableField.d.ts +0 -18
  135. package/lib/components/fields/TableField.js +0 -136
  136. package/lib/components/fields/TagArrayField.d.ts +0 -38
  137. package/lib/components/fields/TagArrayField.js +0 -128
  138. package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +0 -26
  139. package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +0 -81
  140. package/lib/components/fields/UiFieldApplierField.d.ts +0 -30
  141. package/lib/components/fields/UiFieldApplierField.js +0 -106
  142. package/lib/components/fields/UiFieldMapperArrayField.d.ts +0 -42
  143. package/lib/components/fields/UiFieldMapperArrayField.js +0 -121
  144. package/lib/components/fields/UnitCountShorthandField.d.ts +0 -22
  145. package/lib/components/fields/UnitCountShorthandField.js +0 -149
  146. package/lib/components/fields/UnitListShorthandArrayField.d.ts +0 -26
  147. package/lib/components/fields/UnitListShorthandArrayField.js +0 -108
  148. package/lib/components/fields/UnitShorthandField.d.ts +0 -32
  149. package/lib/components/fields/UnitShorthandField.js +0 -220
  150. package/lib/components/templates/ArrayFieldTemplate.d.ts +0 -85
  151. package/lib/components/templates/ArrayFieldTemplate.js +0 -417
  152. package/lib/components/templates/BaseInputTemplate.d.ts +0 -11
  153. package/lib/components/templates/BaseInputTemplate.js +0 -80
  154. package/lib/components/templates/DescriptionField.d.ts +0 -1
  155. package/lib/components/templates/DescriptionField.js +0 -37
  156. package/lib/components/templates/ErrorListTemplate.d.ts +0 -9
  157. package/lib/components/templates/ErrorListTemplate.js +0 -95
  158. package/lib/components/templates/FieldTemplate.d.ts +0 -6
  159. package/lib/components/templates/FieldTemplate.js +0 -112
  160. package/lib/components/templates/ObjectFieldTemplate.d.ts +0 -7
  161. package/lib/components/templates/ObjectFieldTemplate.js +0 -66
  162. package/lib/components/templates/TitleField.d.ts +0 -9
  163. package/lib/components/templates/TitleField.js +0 -51
  164. package/lib/components/widgets/AnyToBooleanWidget.d.ts +0 -20
  165. package/lib/components/widgets/AnyToBooleanWidget.js +0 -49
  166. package/lib/components/widgets/AutosuggestWidget.d.ts +0 -66
  167. package/lib/components/widgets/AutosuggestWidget.js +0 -1127
  168. package/lib/components/widgets/CheckboxWidget.d.ts +0 -37
  169. package/lib/components/widgets/CheckboxWidget.js +0 -139
  170. package/lib/components/widgets/DateTimeWidget.d.ts +0 -62
  171. package/lib/components/widgets/DateTimeWidget.js +0 -251
  172. package/lib/components/widgets/DateWidget.d.ts +0 -23
  173. package/lib/components/widgets/DateWidget.js +0 -41
  174. package/lib/components/widgets/HiddenWidget.d.ts +0 -15
  175. package/lib/components/widgets/HiddenWidget.js +0 -19
  176. package/lib/components/widgets/ImageSelectWidget.d.ts +0 -14
  177. package/lib/components/widgets/ImageSelectWidget.js +0 -57
  178. package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +0 -43
  179. package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +0 -237
  180. package/lib/components/widgets/InputGroupWidget.d.ts +0 -21
  181. package/lib/components/widgets/InputGroupWidget.js +0 -36
  182. package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +0 -21
  183. package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +0 -47
  184. package/lib/components/widgets/NumberWidget.d.ts +0 -13
  185. package/lib/components/widgets/NumberWidget.js +0 -21
  186. package/lib/components/widgets/PlainTextWidget.d.ts +0 -12
  187. package/lib/components/widgets/PlainTextWidget.js +0 -24
  188. package/lib/components/widgets/SelectWidget.d.ts +0 -52
  189. package/lib/components/widgets/SelectWidget.js +0 -158
  190. package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +0 -19
  191. package/lib/components/widgets/SeparatedDateTimeWidget.js +0 -59
  192. package/lib/components/widgets/TaxonImageWidget.d.ts +0 -13
  193. package/lib/components/widgets/TaxonImageWidget.js +0 -30
  194. package/lib/components/widgets/TextSelectWidget.d.ts +0 -25
  195. package/lib/components/widgets/TextSelectWidget.js +0 -94
  196. package/lib/components/widgets/TextareaWidget.d.ts +0 -32
  197. package/lib/components/widgets/TextareaWidget.js +0 -87
  198. package/lib/components/widgets/TimeWidget.d.ts +0 -11
  199. package/lib/components/widgets/TimeWidget.js +0 -19
  200. package/lib/components/widgets/URLWidget.d.ts +0 -14
  201. package/lib/components/widgets/URLWidget.js +0 -12
  202. package/lib/components/widgets/UpperCaseWidget.d.ts +0 -13
  203. package/lib/components/widgets/UpperCaseWidget.js +0 -21
  204. package/lib/index.d.ts +0 -20
  205. package/lib/index.js +0 -50
  206. package/lib/services/blocker-service.d.ts +0 -11
  207. package/lib/services/blocker-service.js +0 -55
  208. package/lib/services/custom-event-service.d.ts +0 -17
  209. package/lib/services/custom-event-service.js +0 -35
  210. package/lib/services/dom-id-service.d.ts +0 -8
  211. package/lib/services/dom-id-service.js +0 -30
  212. package/lib/services/focus-service.d.ts +0 -13
  213. package/lib/services/focus-service.js +0 -60
  214. package/lib/services/id-service.d.ts +0 -22
  215. package/lib/services/id-service.js +0 -130
  216. package/lib/services/key-handler-service.d.ts +0 -56
  217. package/lib/services/key-handler-service.js +0 -184
  218. package/lib/services/root-instance-service.d.ts +0 -25
  219. package/lib/services/root-instance-service.js +0 -49
  220. package/lib/services/settings-service.d.ts +0 -34
  221. package/lib/services/settings-service.js +0 -154
  222. package/lib/services/singleton-map-service.d.ts +0 -23
  223. package/lib/services/singleton-map-service.js +0 -44
  224. package/lib/services/submit-hook-service.d.ts +0 -24
  225. package/lib/services/submit-hook-service.js +0 -73
  226. package/lib/styles.d.ts +0 -1
  227. package/lib/styles.js +0 -4
  228. package/lib/themes/bs3.d.ts +0 -3
  229. package/lib/themes/bs3.js +0 -133
  230. package/lib/themes/bs5.d.ts +0 -3
  231. package/lib/themes/bs5.js +0 -111
  232. package/lib/themes/glyphicon-fa-mapping.d.ts +0 -3
  233. package/lib/themes/glyphicon-fa-mapping.js +0 -271
  234. package/lib/themes/stub.d.ts +0 -3
  235. package/lib/themes/stub.js +0 -82
  236. package/lib/themes/theme.d.ts +0 -233
  237. package/lib/themes/theme.js +0 -2
  238. package/lib/translations.json +0 -847
  239. package/lib/utils.d.ts +0 -171
  240. package/lib/utils.js +0 -1191
  241. package/lib/validation.d.ts +0 -7
  242. package/lib/validation.js +0 -141
  243. package/llol +0 -10
  244. package/llol.pdf +0 -10
  245. package/playwright-report/index.html +0 -62
  246. package/q +0 -196
  247. package/rename.sh +0 -24
  248. package/trip-report.spec.ts +0 -594
@@ -1,440 +0,0 @@
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;
@@ -1,78 +0,0 @@
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";