@luomus/laji-form 15.1.5 → 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 (234) 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
package/lib/utils.js ADDED
@@ -0,0 +1,1185 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.bsSizeToPixels = exports.canAdd = exports.stringifyKeyCombo = exports.decapitalizeFirstLetter = exports.capitalizeFirstLetter = exports.getKeyHandlerTargetId = exports.isDescendant = exports.getBootstrapCols = exports.getNestedUiFieldsList = exports.updateTailUiSchema = exports.getNestedTailUiSchema = exports.keyboardClick = exports.formDataEquals = exports.formDataIsEmpty = exports.filterItemIdsDeeply = exports.filterItemId = exports.filterLajiFormId = exports.syncScroll = exports._syncScroll = exports.shouldSyncScroll = exports.focusAndScroll = exports.focusById = exports.getSchemaElementById = exports.findNearestParentSchemaElemId = exports.focusNextInput = exports.getNextInput = exports.getNextInputInInputs = exports.ReactUtils = exports.findNearestParentTabbableElem = exports.findNearestParentSchemaElem = exports.canFocusNextInput = exports.isTabbableInput = exports.getTabbableFields = exports.isSelect = exports.isMultiSelect = exports.getReactComponentName = exports.parseJSONPointer = exports.isEmptyString = exports.isNullOrUndefined = exports.getInnerUiSchema = exports.getUiOptions = exports.immutableDelete = exports.getUpdateObjectFromJSONPointer = exports.getUpdateObjectFromJSONPath = exports.propertyHasData = exports.hasData = exports.getDefaultFormState = exports.isDefaultData = exports.isHidden = exports.isObject = void 0;
15
+ exports.translate = exports.classNames = exports.getTitle = exports.toJSONPointer = exports.getReversedFormDataIndex = exports.getFormDataIndex = exports.getIdxWithoutOffset = exports.getIdxWithOffset = exports.constructTranslations = exports.filteredErrors = exports.highlightElem = exports.findPointerForLajiFormId = exports.removeLajiFormIds = exports.getAllLajiFormIdsDeeply = exports.addLajiFormIds = exports.getFieldUUID = exports.getUUID = exports.assignUUID = exports.updateFormDataWithJSONPointer = exports.uiSchemaJSONPointer = exports.schemaJSONPointer = exports.idSchemaIdToJSONPointer = exports.JSONPointerToId = exports.checkJSONPointer = exports.parseUiSchemaFromFormDataPointer = exports.parseSchemaFromFormDataPointer = exports.triggerParentComponent = exports.bringRemoteFormData = exports.checkArrayRules = exports.checkRules = exports.formatErrorMessage = exports.formatValue = exports.dictionarify = exports.injectButtons = exports.updateSafelyWithJSONPointer = exports.updateSafelyWithJSONPath = exports.filter = exports.scrollIntoViewIfNeeded = exports.getScrollPositionForScrollIntoViewIfNeeded = exports.getWindowScrolled = exports.applyFunction = exports.pixelsToBsSize = void 0;
16
+ const React = require("react");
17
+ const react_dom_1 = require("react-dom");
18
+ const utils_1 = require("@rjsf/utils");
19
+ const Context_1 = require("./Context");
20
+ const ReactContext_1 = require("./ReactContext");
21
+ const immutability_helper_1 = require("immutability-helper");
22
+ const utils_2 = require("@luomus/laji-map/lib/utils");
23
+ const deepEquals = require("deep-equal");
24
+ const validator_ajv6_1 = require("@rjsf/validator-ajv6");
25
+ exports.isObject = utils_2.isObject;
26
+ function isHidden(uiSchema, property) {
27
+ if (!uiSchema)
28
+ return false;
29
+ if (uiSchema[property])
30
+ uiSchema = uiSchema[property];
31
+ return !uiSchema || uiSchema["ui:widget"] == "HiddenWidget" || uiSchema["ui:field"] == "HiddenField";
32
+ }
33
+ exports.isHidden = isHidden;
34
+ function isDefaultData(formData, schema) {
35
+ switch (schema.type) {
36
+ case "object":
37
+ return !formData || Object.keys(schema.properties).every(field => isDefaultData(formData[field], schema.properties[field]));
38
+ case "array":
39
+ return (Array.isArray(formData) || formData === undefined) && (formData || []).every((item) => isDefaultData(item, schema.items));
40
+ default:
41
+ return formData === getDefaultFormState(schema);
42
+ }
43
+ }
44
+ exports.isDefaultData = isDefaultData;
45
+ function getDefaultFormState(schema, formData, rootSchema) {
46
+ return utils_1.getDefaultFormState(validator_ajv6_1.default, schema, formData, rootSchema);
47
+ }
48
+ exports.getDefaultFormState = getDefaultFormState;
49
+ /**
50
+ * If you use this with schema data, note that this function doesn't check default data.
51
+ */
52
+ function hasData(formData) {
53
+ function hasValue(value) {
54
+ return value !== undefined && value !== null && value !== "";
55
+ }
56
+ if (!hasValue(formData)) {
57
+ return false;
58
+ }
59
+ else {
60
+ if (!Array.isArray(formData))
61
+ formData = [formData];
62
+ return formData.some((data) => {
63
+ if (exports.isObject(data)) {
64
+ return Object.keys(data).some(_field => propertyHasData(_field, data));
65
+ }
66
+ else
67
+ return hasValue(data);
68
+ });
69
+ }
70
+ }
71
+ exports.hasData = hasData;
72
+ /**
73
+ * If you use this with schema data, note that this function doesn't check default data.
74
+ */
75
+ function propertyHasData(field, container) {
76
+ if (!container)
77
+ return false;
78
+ const data = container[field];
79
+ return !!(data &&
80
+ (!exports.isObject(data) || (Object.keys(data).length > 0 && hasData(data))) &&
81
+ (!Array.isArray(data) || (data.length > 0 && hasData(data))));
82
+ }
83
+ exports.propertyHasData = propertyHasData;
84
+ function getUpdateObjectFromJSONPath(path, injection) {
85
+ console.warn("'getUpdateObjectFromJSONPath' works with JSON pointers, not JSON path! This function is deprecated and will be removed in the future, please use 'getUpdateObjectFromJSONPointer' instead");
86
+ return getUpdateObjectFromJSONPointer(path, injection);
87
+ }
88
+ exports.getUpdateObjectFromJSONPath = getUpdateObjectFromJSONPath;
89
+ function getUpdateObjectFromJSONPointer(path, injection) {
90
+ let update = {};
91
+ let updatePointer = update;
92
+ let lastPathName = "";
93
+ let splittedPath = path.split("/").filter(s => !isEmptyString(s));
94
+ if (!splittedPath.length) {
95
+ return update;
96
+ }
97
+ splittedPath.forEach((pathStep, i) => {
98
+ updatePointer[pathStep] = {};
99
+ if (i < splittedPath.length - 1)
100
+ updatePointer = updatePointer[pathStep];
101
+ lastPathName = pathStep;
102
+ });
103
+ updatePointer[lastPathName] = injection;
104
+ return update;
105
+ }
106
+ exports.getUpdateObjectFromJSONPointer = getUpdateObjectFromJSONPointer;
107
+ function immutableDelete(_obj, _delProp) {
108
+ const simple = (obj, delProp) => {
109
+ if (!(delProp in obj)) {
110
+ return obj;
111
+ }
112
+ const newObj = {};
113
+ Object.keys(obj).forEach(prop => {
114
+ if (prop !== delProp)
115
+ newObj[prop] = obj[prop];
116
+ });
117
+ return newObj;
118
+ };
119
+ if (_delProp[0] === "/") {
120
+ const splits = _delProp.split("/");
121
+ const last = splits.pop();
122
+ const container = parseJSONPointer(_obj, "/" + splits.join("/"), !!"safely");
123
+ if (!container || !(last in container)) {
124
+ return _obj;
125
+ }
126
+ return updateSafelyWithJSONPointer(_obj, simple(container, last), "/" + splits.join("/"));
127
+ }
128
+ else {
129
+ return simple(_obj, _delProp);
130
+ }
131
+ }
132
+ exports.immutableDelete = immutableDelete;
133
+ function getUiOptions(container) {
134
+ if (container) {
135
+ const options = container["ui:options"] || container.options;
136
+ return options ? options : {};
137
+ }
138
+ return {};
139
+ }
140
+ exports.getUiOptions = getUiOptions;
141
+ function getInnerUiSchema(parentUiSchema) {
142
+ let _a = parentUiSchema || {}, { uiSchema } = _a, restOfUiSchema = __rest(_a, ["uiSchema"]);
143
+ if (uiSchema && (Context_1.default("VIRTUAL_SCHEMA_NAMES")[uiSchema["ui:field"]] || Context_1.default("SCHEMA_FIELD_WRAPPERS")[uiSchema["ui:field"]]) && parentUiSchema["ui:buttons"]) {
144
+ uiSchema = Object.assign(Object.assign({}, uiSchema), { "ui:buttons": [
145
+ ...(uiSchema["ui:buttons"] || []),
146
+ ...parentUiSchema["ui:buttons"]
147
+ ] });
148
+ }
149
+ return Object.assign(Object.assign(Object.assign({}, restOfUiSchema), { "ui:field": undefined, "ui:settings": undefined, "ui:options": uiSchema ? undefined : restOfUiSchema["ui:options"], "ui:buttons": uiSchema ? undefined : parentUiSchema["ui:buttons"] }), (uiSchema || {}));
150
+ }
151
+ exports.getInnerUiSchema = getInnerUiSchema;
152
+ function isNullOrUndefined(val) {
153
+ return val === null || val === undefined;
154
+ }
155
+ exports.isNullOrUndefined = isNullOrUndefined;
156
+ function isEmptyString(val) {
157
+ return val === "" || isNullOrUndefined(val);
158
+ }
159
+ exports.isEmptyString = isEmptyString;
160
+ function parseJSONPointer(object, jsonPointer, safeMode, strictEmptyPath = false) {
161
+ if (jsonPointer === "" || jsonPointer === "/") {
162
+ return object;
163
+ }
164
+ let splitPath = String(jsonPointer).split("/");
165
+ if (String(jsonPointer)[0] === "/") {
166
+ splitPath = splitPath.splice(1);
167
+ }
168
+ if (!strictEmptyPath) {
169
+ splitPath = splitPath.filter(s => !isEmptyString(s));
170
+ }
171
+ return splitPath.reduce((o, s, i) => {
172
+ if (safeMode && !o || !(s in o)) {
173
+ if (!o)
174
+ o = {};
175
+ if (safeMode === "createParents") {
176
+ o[s] = {};
177
+ }
178
+ else if (i < splitPath.length - 1) {
179
+ return {};
180
+ }
181
+ }
182
+ return o[s];
183
+ }, object);
184
+ }
185
+ exports.parseJSONPointer = parseJSONPointer;
186
+ function getReactComponentName(WrappedComponent) {
187
+ return (WrappedComponent.displayName ||
188
+ WrappedComponent.name ||
189
+ "Component");
190
+ }
191
+ exports.getReactComponentName = getReactComponentName;
192
+ function isMultiSelect(schema, uiSchema) {
193
+ return utils_1.isMultiSelect(validator_ajv6_1.default, schema) && !(schema.type === "array" &&
194
+ uiSchema &&
195
+ uiSchema.items &&
196
+ uiSchema.items["ui:field"]);
197
+ }
198
+ exports.isMultiSelect = isMultiSelect;
199
+ function isSelect(schema) {
200
+ return utils_1.isSelect(validator_ajv6_1.default, schema);
201
+ }
202
+ exports.isSelect = isSelect;
203
+ const SWITCH_CLASS = "laji-form-checkbox-widget-tab-target";
204
+ const IMG_ADD_CLASS = "laji-form-drop-zone";
205
+ const inputTypes = ["input", "select", "textarea"];
206
+ const tabbableSelectors = [
207
+ ...inputTypes,
208
+ `.${SWITCH_CLASS}`,
209
+ `.${IMG_ADD_CLASS}`
210
+ ].map(type => `${type}:not([type="hidden"]):not(:disabled):not([readonly]):not([type="file"]):not(.leaflet-control-layers-selector):not(.laji-map-input)`);
211
+ const tabbableSelectorsQuery = tabbableSelectors.join(", ");
212
+ function getTabbableFields(elem, reverse) {
213
+ const fieldsNodeList = elem.querySelectorAll(tabbableSelectorsQuery);
214
+ let fields = Array.from(fieldsNodeList).filter(node => node.tabIndex !== -1);
215
+ if (reverse)
216
+ fields = fields.reverse();
217
+ return fields;
218
+ }
219
+ exports.getTabbableFields = getTabbableFields;
220
+ function isTabbableInput(elem) {
221
+ return elem.id.match(/^_laji-form_/)
222
+ || inputTypes.includes(elem.tagName.toLowerCase())
223
+ || elem.className.includes(SWITCH_CLASS)
224
+ || elem.className.includes(IMG_ADD_CLASS);
225
+ }
226
+ exports.isTabbableInput = isTabbableInput;
227
+ function canFocusNextInput(root, inputElem) {
228
+ var _a;
229
+ const node = react_dom_1.findDOMNode(root);
230
+ return (((_a = node) === null || _a === void 0 ? void 0 : _a.querySelectorAll) && isTabbableInput(inputElem));
231
+ }
232
+ exports.canFocusNextInput = canFocusNextInput;
233
+ function findNearestParentSchemaElem(elem) {
234
+ while (elem && !("id" in elem ? elem.id : "").match(/^_laji-form_/)) {
235
+ elem = elem.parentNode;
236
+ }
237
+ return elem;
238
+ }
239
+ exports.findNearestParentSchemaElem = findNearestParentSchemaElem;
240
+ function findNearestParentTabbableElem(elem) {
241
+ while (!isTabbableInput(elem)) {
242
+ elem = elem.parentNode;
243
+ }
244
+ return elem;
245
+ }
246
+ exports.findNearestParentTabbableElem = findNearestParentTabbableElem;
247
+ const ReactUtils = (context) => ({
248
+ findNearestParentSchemaElemId: exports.findNearestParentSchemaElemId,
249
+ getSchemaElementById: exports.getSchemaElementById,
250
+ focusById: _focusById(context),
251
+ focusAndScroll: _focusAndScroll(context),
252
+ shouldSyncScroll: _shouldSyncScroll(context),
253
+ syncScroll: exports._syncScroll(context),
254
+ filterItemIdsDeeply: _filterItemIdsDeeply(context),
255
+ formDataIsEmpty: _formDataIsEmpty(context),
256
+ formDataEquals: _formDataEquals(context),
257
+ keyboardClick: _keyboardClick(context),
258
+ getNextInput: exports.getNextInput(context),
259
+ focusNextInput: exports.focusNextInput(context),
260
+ getNextInputInInputs: exports.getNextInputInInputs(context)
261
+ });
262
+ exports.ReactUtils = ReactUtils;
263
+ const getNextInputInInputs = (formContext) => (inputElem, reverseDirection = false, fields) => {
264
+ const formReactNode = formContext.formRef.current;
265
+ const formElem = react_dom_1.findDOMNode(formReactNode);
266
+ if (!formElem) {
267
+ return undefined;
268
+ }
269
+ if (!document.activeElement) {
270
+ return undefined;
271
+ }
272
+ if (!inputElem)
273
+ inputElem = findNearestParentTabbableElem(document.activeElement);
274
+ if (!inputElem) {
275
+ return undefined;
276
+ }
277
+ if (reverseDirection) {
278
+ fields = fields.reverse();
279
+ }
280
+ if (!canFocusNextInput(formElem, inputElem))
281
+ return undefined;
282
+ let found = false;
283
+ for (let field of fields) {
284
+ if (field === inputElem) {
285
+ found = true;
286
+ continue;
287
+ }
288
+ if (found) {
289
+ // Skip hidden fields.
290
+ if (!field.offsetParent) {
291
+ continue;
292
+ }
293
+ return field;
294
+ }
295
+ }
296
+ return undefined;
297
+ };
298
+ exports.getNextInputInInputs = getNextInputInInputs;
299
+ const getNextInput = (formContext) => (inputElem, reverseDirection = false) => {
300
+ const formElem = react_dom_1.findDOMNode(formContext.formRef.current);
301
+ const fields = getTabbableFields(formElem);
302
+ return formContext.utils.getNextInputInInputs(inputElem, reverseDirection, fields);
303
+ };
304
+ exports.getNextInput = getNextInput;
305
+ const focusNextInput = (formContext) => (reverseDirection = false) => {
306
+ const formReactNode = formContext.formRef.current;
307
+ if (!formReactNode) {
308
+ throw new Error("focusNextInput() didn't find form ref");
309
+ }
310
+ const { uiSchema = {} } = formReactNode.props;
311
+ if (uiSchema.autoFocus === false) {
312
+ return false;
313
+ }
314
+ const width = pixelsToBsSize(window.outerWidth);
315
+ if (width === "xs")
316
+ return false;
317
+ const field = formContext.utils.getNextInput(document.activeElement, reverseDirection);
318
+ if (field) {
319
+ field.focus();
320
+ return true;
321
+ }
322
+ return false;
323
+ };
324
+ exports.focusNextInput = focusNextInput;
325
+ const findNearestParentSchemaElemId = (elem) => {
326
+ const nearestParentSchemaElem = findNearestParentSchemaElem(elem) || document.getElementById("_laji-form_root");
327
+ return nearestParentSchemaElem ? nearestParentSchemaElem.id.replace("_laji-form_", "") : undefined;
328
+ };
329
+ exports.findNearestParentSchemaElemId = findNearestParentSchemaElemId;
330
+ const getSchemaElementById = (id) => {
331
+ return document.getElementById(`_laji-form_${id}`);
332
+ };
333
+ exports.getSchemaElementById = getSchemaElementById;
334
+ const _focusById = (context) => (id, focus = true) => {
335
+ const elem = exports.getSchemaElementById(id);
336
+ if (elem && document.body.contains(elem)) {
337
+ const tabbableFields = getTabbableFields(elem);
338
+ if (tabbableFields && tabbableFields.length) {
339
+ focus && tabbableFields[0].focus();
340
+ scrollIntoViewIfNeeded(elem, context.topOffset, context.bottomOffset);
341
+ const rootContext = Context_1.default(context.contextId);
342
+ rootContext.lastIdToFocus = id; // Mark for components that manipulate scroll positions
343
+ rootContext.windowScrolled = getWindowScrolled();
344
+ return true;
345
+ }
346
+ }
347
+ return false;
348
+ };
349
+ const focusById = (context, id, focus) => _focusById(context)(id, focus);
350
+ exports.focusById = focusById;
351
+ const _focusAndScroll = (context) => (idToFocus, idToScroll, focus = true) => {
352
+ const { contextId, topOffset, bottomOffset } = context;
353
+ const _context = Context_1.default(contextId);
354
+ if (idToFocus === undefined && idToScroll === undefined)
355
+ return;
356
+ if (idToFocus && !context.utils.focusById(getKeyHandlerTargetId(idToFocus, _context), focus))
357
+ return false;
358
+ if (idToScroll) {
359
+ const elemToScroll = document.getElementById(getKeyHandlerTargetId(idToScroll, _context));
360
+ const elemToFocus = exports.getSchemaElementById(getKeyHandlerTargetId(idToFocus, _context));
361
+ if (!elemToScroll || !elemToFocus) {
362
+ return end();
363
+ }
364
+ const wouldScrollTo = getScrollPositionForScrollIntoViewIfNeeded(elemToScroll, topOffset, bottomOffset);
365
+ const scrollAmount = wouldScrollTo - getWindowScrolled();
366
+ const { top } = elemToFocus.getBoundingClientRect();
367
+ const viewTopDistanceFromTop = top - scrollAmount;
368
+ // Don't scroll if scrolling would hide focused elem top.
369
+ if (viewTopDistanceFromTop < topOffset) {
370
+ return end();
371
+ }
372
+ else {
373
+ scrollIntoViewIfNeeded(elemToScroll, topOffset, bottomOffset);
374
+ }
375
+ }
376
+ return end();
377
+ function end() {
378
+ _context.lastIdToScroll = idToScroll;
379
+ _context.lastIdToFocus = idToFocus;
380
+ _context.windowScrolled = getWindowScrolled();
381
+ return true;
382
+ }
383
+ };
384
+ const focusAndScroll = (context, idToFocus, idToScroll, focus) => _focusAndScroll(context)(idToFocus, idToScroll, focus);
385
+ exports.focusAndScroll = focusAndScroll;
386
+ const _shouldSyncScroll = (context) => () => {
387
+ return Context_1.default(context.contextId).windowScrolled === getWindowScrolled();
388
+ };
389
+ const shouldSyncScroll = (context) => _shouldSyncScroll(context)();
390
+ exports.shouldSyncScroll = shouldSyncScroll;
391
+ const _syncScroll = (context) => (force = false) => {
392
+ if (force || exports.shouldSyncScroll(context)) {
393
+ const { lastIdToFocus, lastIdToScroll } = Context_1.default(context.contextId);
394
+ exports.focusAndScroll(context, lastIdToFocus, lastIdToScroll, false);
395
+ }
396
+ };
397
+ exports._syncScroll = _syncScroll;
398
+ const syncScroll = (context, force) => exports._syncScroll(context)(force);
399
+ exports.syncScroll = syncScroll;
400
+ const filterLajiFormId = (item) => {
401
+ if (item && item._lajiFormId) {
402
+ const { _lajiFormId } = item, _item = __rest(item, ["_lajiFormId"]); // eslint-disable-line @typescript-eslint/no-unused-vars
403
+ item = _item;
404
+ }
405
+ return item;
406
+ };
407
+ exports.filterLajiFormId = filterLajiFormId;
408
+ const filterItemId = (item) => {
409
+ if (item && (item._lajiFormId || item.id)) {
410
+ const { _lajiFormId, id } = item, _item = __rest(item, ["_lajiFormId", "id"]); // eslint-disable-line @typescript-eslint/no-unused-vars
411
+ item = _item;
412
+ }
413
+ return item;
414
+ };
415
+ exports.filterItemId = filterItemId;
416
+ const _filterItemIdsDeeply = (context) => (item, idSchemaId) => {
417
+ const tmpIdTree = context.services.ids.getRelativeTmpIdTree(idSchemaId);
418
+ let [_item] = walkFormDataWithIdTree(item, tmpIdTree, exports.filterItemId);
419
+ return _item;
420
+ };
421
+ const filterItemIdsDeeply = (item, context, idSchemaId) => _filterItemIdsDeeply(context)(item, idSchemaId);
422
+ exports.filterItemIdsDeeply = filterItemIdsDeeply;
423
+ const _formDataIsEmpty = (context) => (props) => {
424
+ const tmpIdTree = context.services.ids.getRelativeTmpIdTree(props.idSchema.$id);
425
+ let [item] = walkFormDataWithIdTree(props.formData, tmpIdTree, exports.filterItemId);
426
+ return deepEquals(item, getDefaultFormState(props.schema, undefined, props.registry.rootSchema));
427
+ };
428
+ const formDataIsEmpty = (props, context) => _formDataIsEmpty(context)(props);
429
+ exports.formDataIsEmpty = formDataIsEmpty;
430
+ const _formDataEquals = (context) => (f1, f2, id) => {
431
+ const tmpIdTree = context.services.ids.getRelativeTmpIdTree(id);
432
+ const [_f1, _f2] = [f1, f2].map(i => walkFormDataWithIdTree(i, tmpIdTree, exports.filterItemId)[0]);
433
+ return deepEquals(_f1, _f2);
434
+ };
435
+ const formDataEquals = (f1, f2, context, id) => {
436
+ return _formDataEquals(context)(f1, f2, id);
437
+ };
438
+ exports.formDataEquals = formDataEquals;
439
+ const _keyboardClick = ({ contextId }) => (fn) => {
440
+ return (e) => {
441
+ var _a, _b;
442
+ let keys = [" ", "Enter"];
443
+ if ((_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.matches) === null || _b === void 0 ? void 0 : _b.call(_a, tabbableSelectorsQuery)) {
444
+ const { shortcuts } = Context_1.default(contextId);
445
+ keys = keys.filter(k => !(shortcuts === null || shortcuts === void 0 ? void 0 : shortcuts[k]));
446
+ }
447
+ if (keys.every(k => e.key !== k)) {
448
+ return;
449
+ }
450
+ e.preventDefault();
451
+ e.stopPropagation();
452
+ fn(e);
453
+ };
454
+ };
455
+ const keyboardClick = (fn, context) => {
456
+ return _keyboardClick(context)(fn);
457
+ };
458
+ exports.keyboardClick = keyboardClick;
459
+ function getNestedTailUiSchema(uiSchema) {
460
+ while (uiSchema && uiSchema.uiSchema) {
461
+ uiSchema = uiSchema.uiSchema;
462
+ }
463
+ return uiSchema;
464
+ }
465
+ exports.getNestedTailUiSchema = getNestedTailUiSchema;
466
+ function updateTailUiSchema(uiSchema, updateObject) {
467
+ let tailPointer = {};
468
+ let root = tailPointer;
469
+ let uiSchemaPointer = uiSchema;
470
+ while (uiSchemaPointer.uiSchema) {
471
+ uiSchemaPointer = uiSchemaPointer.uiSchema;
472
+ tailPointer.uiSchema = {};
473
+ if (uiSchemaPointer.uiSchema)
474
+ tailPointer = tailPointer.uiSchema;
475
+ }
476
+ tailPointer.uiSchema = updateObject;
477
+ return immutability_helper_1.default(uiSchema, root);
478
+ }
479
+ exports.updateTailUiSchema = updateTailUiSchema;
480
+ function getNestedUiFieldsList(uiSchema) {
481
+ const list = [];
482
+ while (uiSchema.uiSchema && uiSchema.uiSchema["ui:field"]) {
483
+ list.push(uiSchema.uiSchema["ui:field"]);
484
+ uiSchema = uiSchema.uiSchema;
485
+ }
486
+ return list;
487
+ }
488
+ exports.getNestedUiFieldsList = getNestedUiFieldsList;
489
+ function getBootstrapCols(width) {
490
+ return ["lg", "md", "sm", "xs"].reduce((o, c) => {
491
+ o[c] = width;
492
+ return o;
493
+ }, {});
494
+ }
495
+ exports.getBootstrapCols = getBootstrapCols;
496
+ function isDescendant(parent, child) {
497
+ let node = child.parentNode;
498
+ while (node != null) {
499
+ if (node == parent) {
500
+ return true;
501
+ }
502
+ node = node.parentNode;
503
+ }
504
+ return false;
505
+ }
506
+ exports.isDescendant = isDescendant;
507
+ function getKeyHandlerTargetId(target = "", context, formData) {
508
+ var _a;
509
+ while (target.match(/%\{([^{}]*)\}/)) {
510
+ const path = ((_a = /%\{([^{}]*)\}/.exec(target)) === null || _a === void 0 ? void 0 : _a[1]) || "";
511
+ if (!path.startsWith("context") && !path.startsWith("formData"))
512
+ throw Error("Should evaluate 'context' or 'formData'");
513
+ target = target.replace(`%{${path}}`, eval(path));
514
+ }
515
+ return target;
516
+ }
517
+ exports.getKeyHandlerTargetId = getKeyHandlerTargetId;
518
+ function capitalizeFirstLetter(string) {
519
+ return string.charAt(0).toUpperCase() + string.slice(1);
520
+ }
521
+ exports.capitalizeFirstLetter = capitalizeFirstLetter;
522
+ function decapitalizeFirstLetter(string) {
523
+ return string.charAt(0).toLowerCase() + string.slice(1);
524
+ }
525
+ exports.decapitalizeFirstLetter = decapitalizeFirstLetter;
526
+ function stringifyKeyCombo(keyCombo = "") {
527
+ return keyCombo.split("+").map(key => {
528
+ if (key === " ")
529
+ key = "space";
530
+ return capitalizeFirstLetter(key);
531
+ }).join(" + ");
532
+ }
533
+ exports.stringifyKeyCombo = stringifyKeyCombo;
534
+ function canAdd(props) {
535
+ return (!("canAdd" in props) || props.canAdd) && getUiOptions(props.uiSchema).canAdd !== false;
536
+ }
537
+ exports.canAdd = canAdd;
538
+ function bsSizeToPixels(bsSize) {
539
+ switch (bsSize) {
540
+ case "lg":
541
+ return 1200;
542
+ case "md":
543
+ return 992;
544
+ case "sm":
545
+ return 768;
546
+ case "xs":
547
+ return 576;
548
+ default:
549
+ throw new Error(`Unknown bootstrap size ${bsSize}. Should be one of 'lg', 'md', 'sm' or 'xs'`);
550
+ }
551
+ }
552
+ exports.bsSizeToPixels = bsSizeToPixels;
553
+ function pixelsToBsSize(pixels) {
554
+ if (pixels < 576) {
555
+ return "xs";
556
+ }
557
+ else if (pixels < 768) {
558
+ return "sm";
559
+ }
560
+ else if (pixels < 992) {
561
+ return "md";
562
+ }
563
+ else if (pixels < 1200) {
564
+ return "lg";
565
+ }
566
+ return "";
567
+ }
568
+ exports.pixelsToBsSize = pixelsToBsSize;
569
+ function applyFunction(props) {
570
+ let { "ui:functions": functions, "ui:childFunctions": childFunctions } = (props.uiSchema || {});
571
+ const objectOrArrayAsArray = (item) => (item ?
572
+ (Array.isArray(item) ?
573
+ item :
574
+ [item]) :
575
+ []);
576
+ if (childFunctions) {
577
+ functions = [
578
+ { "ui:field": "UiFieldMapperArrayField", "ui:options": { functions: objectOrArrayAsArray(childFunctions) } },
579
+ ...objectOrArrayAsArray(functions)
580
+ ];
581
+ }
582
+ if (!functions)
583
+ return props;
584
+ const computedProps = ((Array.isArray(functions)) ? functions : [functions]).reduce((_props, { "ui:field": uiField, "ui:options": uiOptions }) => {
585
+ _props = Object.assign(Object.assign({}, _props), { uiSchema: Object.assign(Object.assign({}, _props.uiSchema), { "ui:field": uiField, "ui:options": uiOptions, uiSchema: undefined }) });
586
+ const { state = {} } = new props.registry.fields[uiField](_props);
587
+ return Object.assign(Object.assign({}, _props), state);
588
+ }, Object.assign(Object.assign({}, props), { formContext: props.registry.formContext }));
589
+ return Object.assign(Object.assign({}, computedProps), { uiSchema: Object.assign(Object.assign({}, computedProps.uiSchema), { "ui:functions": undefined, "ui:childFunctions": undefined, "ui:field": props.uiSchema["ui:field"], "ui:options": props.uiSchema["ui:options"], uiSchema: props.uiSchema.uiSchema }) });
590
+ }
591
+ exports.applyFunction = applyFunction;
592
+ function getWindowScrolled() {
593
+ return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
594
+ }
595
+ exports.getWindowScrolled = getWindowScrolled;
596
+ function getScrollPositionForScrollIntoViewIfNeeded(elem, topOffset = 0, bottomOffset = 0) {
597
+ if (!elem)
598
+ return getWindowScrolled();
599
+ const rect = elem.getBoundingClientRect();
600
+ const html = document.documentElement;
601
+ const height = elem.scrollHeight;
602
+ const inView = (rect.top >= topOffset &&
603
+ rect.bottom <= (window.innerHeight || html.clientHeight) - bottomOffset);
604
+ const elemTopDistFromViewportTop = rect.top;
605
+ const viewportHeight = (window.innerHeight || html.clientHeight);
606
+ const elemBottomDistFromViewportBottom = -(elemTopDistFromViewportTop + height - viewportHeight);
607
+ const pageScrolled = getWindowScrolled();
608
+ if (inView)
609
+ return pageScrolled;
610
+ // Priorize scrolling the top of the element into view if showing the bottom would obscure the top of the element.
611
+ if (pageScrolled + elemTopDistFromViewportTop - topOffset > elemTopDistFromViewportTop) {
612
+ return pageScrolled + elemTopDistFromViewportTop - topOffset;
613
+ }
614
+ else {
615
+ return pageScrolled - elemBottomDistFromViewportBottom + bottomOffset;
616
+ }
617
+ }
618
+ exports.getScrollPositionForScrollIntoViewIfNeeded = getScrollPositionForScrollIntoViewIfNeeded;
619
+ function scrollIntoViewIfNeeded(elem, topOffset = 0, bottomOffset = 0) {
620
+ window.scrollTo(0, getScrollPositionForScrollIntoViewIfNeeded(elem, topOffset, bottomOffset));
621
+ }
622
+ exports.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded;
623
+ function filter(properties, filter, filterType = "blacklist", getValue) {
624
+ const filterDictionary = {};
625
+ filter.forEach(_enum => { filterDictionary[_enum] = true; });
626
+ const filterFn = (item) => {
627
+ const value = getValue ? getValue(item) : item;
628
+ return filterDictionary[value];
629
+ };
630
+ return properties.filter(filterType === "whitelist" ? filterFn : e => !filterFn(e));
631
+ }
632
+ exports.filter = filter;
633
+ function updateSafelyWithJSONPath(obj, value, path, immutably, createNew) {
634
+ console.warn("'updateSafelyWithJSONPath' works with JSON pointers, not JSON path! This function is deprecated and will be removed in the future, please use 'updateSafelyWithJSONPointer' instead");
635
+ return updateSafelyWithJSONPointer(obj, value, path, immutably, createNew);
636
+ }
637
+ exports.updateSafelyWithJSONPath = updateSafelyWithJSONPath;
638
+ function updateSafelyWithJSONPointer(obj, value, path, immutably = true, createNew = () => ({})) {
639
+ if (path === "/") {
640
+ return value;
641
+ }
642
+ if (!immutably) {
643
+ const splitted = path.split("/").filter(s => !isEmptyString(s));
644
+ splitted.reduce((o, split, i) => {
645
+ if (i === splitted.length - 1) {
646
+ o[split] = value;
647
+ return;
648
+ }
649
+ if (!o[split]) {
650
+ o[split] = createNew(o, split);
651
+ }
652
+ return o[split];
653
+ }, obj);
654
+ return obj;
655
+ }
656
+ let injectionTarget = false;
657
+ try {
658
+ injectionTarget = parseJSONPointer(obj, path);
659
+ }
660
+ catch (e) {
661
+ injectionTarget = makePath(injectionTarget);
662
+ }
663
+ // If path for injection doesn't exist, we create it immutably.
664
+ if (!injectionTarget) {
665
+ injectionTarget = makePath(injectionTarget);
666
+ }
667
+ const updateObject = getUpdateObjectFromJSONPointer(path, { $set: value });
668
+ return immutability_helper_1.default(obj, updateObject);
669
+ function makePath(injectionTarget) {
670
+ const splitPath = path.split("/").filter(s => !isEmptyString(s));
671
+ let _splitPath = "";
672
+ splitPath.reduce((o, split) => {
673
+ _splitPath += `/${split}`;
674
+ if (!o[split]) {
675
+ obj = immutability_helper_1.default(obj, getUpdateObjectFromJSONPointer(_splitPath, { $set: createNew(obj, _splitPath, o, split) }));
676
+ }
677
+ const next = parseJSONPointer(obj, _splitPath);
678
+ injectionTarget = next;
679
+ return next;
680
+ }, obj);
681
+ return injectionTarget;
682
+ }
683
+ }
684
+ exports.updateSafelyWithJSONPointer = updateSafelyWithJSONPointer;
685
+ function injectButtons(uiSchema, buttons, buttonsPath) {
686
+ const existingButtons = parseJSONPointer(uiSchema, `${buttonsPath}/ui:options/buttons`);
687
+ return updateSafelyWithJSONPointer(uiSchema, existingButtons ? [...existingButtons, ...buttons] : buttons, `${buttonsPath}/ui:options/buttons`);
688
+ }
689
+ exports.injectButtons = injectButtons;
690
+ function dictionarify(array, getKey, getValue) {
691
+ return array.reduce((o, k) => {
692
+ o[getKey ? getKey(k) : k] = getValue ? getValue(k) : true;
693
+ return o;
694
+ }, {});
695
+ }
696
+ exports.dictionarify = dictionarify;
697
+ const tableFormatters = {
698
+ unknownTaxon: (item, formatted, options, parentProps = {}) => (isEmptyString(item) || (parentProps.formData || {})[options.idField])
699
+ ? formatted
700
+ : (React.createElement(ReactContext_1.default.Consumer, null, ({ theme: { Glyphicon } }) => React.createElement("span", null,
701
+ formatted,
702
+ " ",
703
+ React.createElement("span", { className: "text-warning" },
704
+ React.createElement(Glyphicon, { glyph: "warning-sign" })))))
705
+ };
706
+ function formatValue(props, _formatter, parentProps) {
707
+ let { formData, uiSchema = {}, schema, registry } = props;
708
+ let formatter = undefined;
709
+ let formatterComponent = undefined;
710
+ if (uiSchema["ui:widget"])
711
+ formatterComponent = registry.widgets[uiSchema["ui:widget"]];
712
+ else if (schema.type === "boolean")
713
+ formatterComponent = registry.widgets.CheckboxWidget;
714
+ else if (uiSchema["ui:field"])
715
+ formatterComponent = registry.fields[uiSchema["ui:field"]];
716
+ if (formatterComponent && formatterComponent.prototype && formatterComponent.prototype.formatValue) {
717
+ formatter = formatterComponent.prototype.formatValue;
718
+ }
719
+ else if (formatterComponent && formatterComponent.prototype && formatterComponent.prototype.__proto__ && formatterComponent.prototype.__proto__.formatValue) {
720
+ formatter = formatterComponent.prototype.__proto__.formatValue;
721
+ }
722
+ const arrayJoiner = (value, i, length, separator = "; ") => {
723
+ const comma = React.createElement(React.Fragment, { key: `_${i}` }, separator);
724
+ return i < length - 1
725
+ ? [value, comma] : [value];
726
+ };
727
+ let formatted = formData;
728
+ if (formatter) {
729
+ formatted = formatter(formData, getUiOptions(uiSchema), props, parentProps);
730
+ }
731
+ else if (isEmptyString(formData)) {
732
+ formatted = "";
733
+ }
734
+ else if (isMultiSelect(schema)) {
735
+ formatted = formData.map((_val) => schema.items.oneOf.find((one) => one.const === _val).title).join(", ");
736
+ }
737
+ else if (schema.type === "object") {
738
+ const keys = Object.keys(formData);
739
+ return keys.map((_col, i) => {
740
+ const child = React.createElement(React.Fragment, { key: _col }, formatValue(Object.assign(Object.assign({}, props), { schema: schema.properties[_col], uiSchema: uiSchema[_col], formData: formData[_col] })));
741
+ return arrayJoiner(child, i, keys.length);
742
+ });
743
+ }
744
+ else if (schema.type === "array") {
745
+ formatted = React.createElement("span", { className: "single-active-array-table-array" }, formData.map((_val, i) => {
746
+ const child = React.createElement(React.Fragment, { key: i }, formatValue(Object.assign(Object.assign({}, props), { schema: props.schema.items, uiSchema: uiSchema.items, formData: _val })));
747
+ return arrayJoiner(child, i, formData.length, "; ");
748
+ }));
749
+ }
750
+ else if (isSelect(schema)) {
751
+ formatted = isEmptyString(formData) ? formData : schema.oneOf.find((one) => one.const === formData).title;
752
+ }
753
+ else if (schema.type === "boolean") {
754
+ formatted = props.formContext.translations[formData ? "yes" : "no"];
755
+ }
756
+ if (_formatter) {
757
+ formatted = tableFormatters[_formatter.formatter](formData, formatted, _formatter, parentProps);
758
+ }
759
+ return formatted;
760
+ }
761
+ exports.formatValue = formatValue;
762
+ const formatErrorMessage = (msg) => msg.replace(/^\[.*\]/, "");
763
+ exports.formatErrorMessage = formatErrorMessage;
764
+ function checkRules(rules, props, cache, prop = "formData") {
765
+ const passes = (Array.isArray(rules) ? rules : [rules]).every((rule, idx) => {
766
+ let passes;
767
+ // BW compatibility for old string rule
768
+ if (rule === "isAdmin") {
769
+ rule = { rule: "isAdmin" };
770
+ }
771
+ else if (rule === "isEdit") {
772
+ rule = { rule: "isEdit" };
773
+ }
774
+ const { field, regexp, valueIn, valueIncludes, valueLengthLessThan, rule: _rule } = rule;
775
+ if (_rule) {
776
+ if (_rule === "isAdmin") {
777
+ passes = props.formContext.uiSchemaContext.isAdmin;
778
+ }
779
+ else if (_rule === "isEdit") {
780
+ passes = props.formContext.uiSchemaContext.isEdit;
781
+ }
782
+ }
783
+ else {
784
+ let value = parseJSONPointer(props[prop] || {}, field);
785
+ if (value === undefined)
786
+ value = "";
787
+ if (regexp) {
788
+ passes = `${value}`.match(new RegExp(regexp));
789
+ }
790
+ else if (valueIn) {
791
+ if (cache) {
792
+ if (!cache[idx]) {
793
+ cache[idx] = dictionarify(valueIn);
794
+ }
795
+ passes = cache[idx][value];
796
+ }
797
+ else {
798
+ passes = dictionarify(valueIn)[value];
799
+ }
800
+ }
801
+ else if (valueIncludes !== undefined) {
802
+ passes = value.includes(valueIncludes);
803
+ }
804
+ else if (valueLengthLessThan !== undefined) {
805
+ passes = value.length < valueLengthLessThan;
806
+ }
807
+ }
808
+ return rule.complement ? !passes : passes;
809
+ });
810
+ return cache ? { passes, cache } : passes;
811
+ }
812
+ exports.checkRules = checkRules;
813
+ function checkArrayRules(rules, props, idx, cache, prop = "formData") {
814
+ const arrayRules = (Array.isArray(rules) ? rules : [rules]).filter(rule => ["isLast", "idx"].some(r => r in rule));
815
+ const passes = arrayRules.every(rule => {
816
+ let passes;
817
+ if ("isLast" in rule) {
818
+ passes = (idx === props.formData.length - 1) === rule.isLast;
819
+ }
820
+ else if ("idx" in rule) {
821
+ passes = idx === rule.idx;
822
+ }
823
+ if (passes !== undefined) {
824
+ return rule.complement ? !passes : passes;
825
+ }
826
+ return true;
827
+ });
828
+ const nonArrayRules = (Array.isArray(rules) ? rules : [rules]).filter(rule => !arrayRules.includes(rule));
829
+ if (nonArrayRules.length) {
830
+ const nonArrayRulesCheck = checkRules(nonArrayRules, Object.assign(Object.assign({}, props), { formData: props.formData[idx] }), cache, prop);
831
+ const allPass = passes && cache ? nonArrayRulesCheck.passes : nonArrayRulesCheck;
832
+ if (cache) {
833
+ return { passes: allPass, cache };
834
+ }
835
+ else {
836
+ return allPass;
837
+ }
838
+ }
839
+ else {
840
+ return cache ? { cache, passes } : passes;
841
+ }
842
+ }
843
+ exports.checkArrayRules = checkArrayRules;
844
+ function bringRemoteFormData(formData, formContext) {
845
+ if (formContext.formDataTransformers) {
846
+ return formContext.formDataTransformers.reduce((formData, { "ui:field": uiField, props: fieldProps }) => {
847
+ const { state = {} } = new fieldProps.registry.fields[uiField](Object.assign(Object.assign({}, fieldProps), { formData }));
848
+ return state.formData;
849
+ }, formData);
850
+ }
851
+ else {
852
+ return formData;
853
+ }
854
+ }
855
+ exports.bringRemoteFormData = bringRemoteFormData;
856
+ function triggerParentComponent(eventName, e, props) {
857
+ if (props && props[eventName]) {
858
+ e.persist && e.persist();
859
+ props[eventName](e);
860
+ }
861
+ }
862
+ exports.triggerParentComponent = triggerParentComponent;
863
+ function parseSchemaFromFormDataPointer(schema, pointer) {
864
+ const splits = pointer.split("/").filter(s => !isEmptyString(s));
865
+ const value = splits.reduce((o, s) => {
866
+ if (!isNaN(parseInt(s))) {
867
+ return o.items;
868
+ }
869
+ if (o.type === "array" && o.items.properties[s])
870
+ return o.items.properties[s];
871
+ if (o.type === "array")
872
+ return o.items;
873
+ return o.properties[s];
874
+ }, schema);
875
+ return value;
876
+ }
877
+ exports.parseSchemaFromFormDataPointer = parseSchemaFromFormDataPointer;
878
+ function parseUiSchemaFromFormDataPointer(uiSchema, pointer) {
879
+ const splits = pointer.split("/").filter(s => !isEmptyString(s));
880
+ return splits.reduce((o, s) => {
881
+ if (!isNaN(parseInt(s))) {
882
+ return o.items;
883
+ }
884
+ if (o && o.items)
885
+ return o.items[s];
886
+ return o ? o[s] : {};
887
+ }, uiSchema);
888
+ }
889
+ exports.parseUiSchemaFromFormDataPointer = parseUiSchemaFromFormDataPointer;
890
+ function checkJSONPointer(obj, pointer) {
891
+ if (!obj)
892
+ return false;
893
+ const splits = pointer.split("/").filter(s => !isEmptyString(s));
894
+ try {
895
+ let _pointer = obj;
896
+ return splits.every(split => {
897
+ const exists = split in _pointer;
898
+ _pointer = _pointer[split];
899
+ return exists;
900
+ });
901
+ }
902
+ catch (e) {
903
+ return false;
904
+ }
905
+ }
906
+ exports.checkJSONPointer = checkJSONPointer;
907
+ const JSONPointerToId = (fieldName) => fieldName[0] === "/" ? fieldName.replace(/(?!^)\//g, "_").substr(1) : fieldName;
908
+ exports.JSONPointerToId = JSONPointerToId;
909
+ const idSchemaIdToJSONPointer = (id) => id.replace(/root_|_/g, "/");
910
+ exports.idSchemaIdToJSONPointer = idSchemaIdToJSONPointer;
911
+ function schemaJSONPointer(schema, JSONPointer) {
912
+ if (JSONPointer[0] !== "/") {
913
+ JSONPointer = `/${JSONPointer}`;
914
+ }
915
+ let schemaPointer = schema;
916
+ return JSONPointer.split("/").filter(s => !isEmptyString(s)).reduce((path, s) => {
917
+ if (schemaPointer[s]) {
918
+ schemaPointer = schemaPointer[s];
919
+ return `${path}/${s}`;
920
+ }
921
+ else if (!isNaN(+s) && schemaPointer.items) {
922
+ schemaPointer = schemaPointer.items;
923
+ return `${path}/items`;
924
+ }
925
+ else if (schemaPointer.properties && schemaPointer.properties[s]) {
926
+ schemaPointer = schemaPointer.properties[s];
927
+ return `${path}/properties/${s}`;
928
+ }
929
+ return undefined;
930
+ }, "");
931
+ }
932
+ exports.schemaJSONPointer = schemaJSONPointer;
933
+ function uiSchemaJSONPointer(schema, JSONPointer) {
934
+ if (JSONPointer[0] !== "/")
935
+ return JSONPointer;
936
+ let schemaPointer = schema;
937
+ return JSONPointer.split("/").filter(s => !isEmptyString(s)).reduce((path, s) => {
938
+ if (schemaPointer[s]) {
939
+ schemaPointer = schemaPointer[s];
940
+ return `${path}/${s}`;
941
+ }
942
+ else if (schemaPointer.properties && schemaPointer.properties[s]) {
943
+ schemaPointer = schemaPointer.properties[s];
944
+ return `${path}/${s}`;
945
+ }
946
+ else if (schemaPointer.items.properties && schemaPointer.items.properties[s]) {
947
+ schemaPointer = schemaPointer.items.properties[s];
948
+ return `${path}/items/${s}`;
949
+ }
950
+ else if (!isNaN(+s) && schemaPointer.items) {
951
+ schemaPointer = schemaPointer.items;
952
+ return `${path}/items`;
953
+ }
954
+ return undefined;
955
+ }, "");
956
+ }
957
+ exports.uiSchemaJSONPointer = uiSchemaJSONPointer;
958
+ function updateFormDataWithJSONPointer(schemaProps, value, path) {
959
+ if (path === "/") {
960
+ return value;
961
+ }
962
+ return updateSafelyWithJSONPointer(schemaProps.formData, value, path, !!"immutably", (__formData, _path) => {
963
+ const schemaPointer = schemaJSONPointer(schemaProps.schema, _path);
964
+ if (schemaPointer === undefined) {
965
+ throw new Error(`Bad JSON Schema pointer '${schemaPointer}!`);
966
+ }
967
+ const _schema = parseJSONPointer(schemaProps.schema, schemaPointer);
968
+ let _default = getDefaultFormState(_schema, undefined, schemaProps.registry.rootSchema);
969
+ if (!_default && _schema.type === "array") {
970
+ return [];
971
+ }
972
+ return _default;
973
+ });
974
+ }
975
+ exports.updateFormDataWithJSONPointer = updateFormDataWithJSONPointer;
976
+ let uuid = 0;
977
+ const assignUUID = (item, immutably = false) => {
978
+ if (exports.isObject(item) && !item.id && !item._lajiFormId) {
979
+ uuid++;
980
+ if (immutably) {
981
+ return Object.assign(Object.assign({}, item), { _lajiFormId: uuid });
982
+ }
983
+ else {
984
+ item._lajiFormId = uuid;
985
+ return item;
986
+ }
987
+ }
988
+ return item;
989
+ };
990
+ exports.assignUUID = assignUUID;
991
+ const getUUID = (item) => item ? (item.id || item._lajiFormId) : undefined;
992
+ exports.getUUID = getUUID;
993
+ /**
994
+ * Return item UUID or the parent UUID
995
+ **/
996
+ const getFieldUUID = (props) => exports.getUUID(props.formData) || props.formContext._parentLajiFormId || "root";
997
+ exports.getFieldUUID = getFieldUUID;
998
+ function walkFormDataWithIdTree(_formData, tree, itemOperator) {
999
+ const ids = {};
1000
+ const walk = (_formData, tree) => {
1001
+ if (!tree)
1002
+ return _formData;
1003
+ const { _hasId } = tree, _tree = __rest(tree, ["_hasId"]);
1004
+ if (_hasId && exports.isObject(_formData)) {
1005
+ _formData = itemOperator ? itemOperator(_formData) : _formData;
1006
+ }
1007
+ if (Object.keys(_tree).length && exports.isObject(_formData)) {
1008
+ return Object.keys(_formData).reduce((f, k) => {
1009
+ if (tree[k]) {
1010
+ f[k] = walk(_formData[k], tree[k]);
1011
+ }
1012
+ else {
1013
+ f[k] = _formData[k];
1014
+ }
1015
+ return f;
1016
+ }, {});
1017
+ }
1018
+ else if (tree && Array.isArray(_formData)) {
1019
+ return _formData.map(item => {
1020
+ item = walk(item, tree);
1021
+ item = itemOperator ? itemOperator(item) : item;
1022
+ if (exports.getUUID(item)) {
1023
+ ids[exports.getUUID(item)] = true;
1024
+ }
1025
+ return item;
1026
+ });
1027
+ }
1028
+ return _formData;
1029
+ };
1030
+ const formData = walk(_formData, tree);
1031
+ return [formData, ids];
1032
+ }
1033
+ function addLajiFormIds(_formData, tree, immutably = true) {
1034
+ const itemOperator = (item) => exports.assignUUID(item, immutably);
1035
+ return walkFormDataWithIdTree(_formData, tree, itemOperator);
1036
+ }
1037
+ exports.addLajiFormIds = addLajiFormIds;
1038
+ function getAllLajiFormIdsDeeply(_formData, tree) {
1039
+ return walkFormDataWithIdTree(_formData, tree)[1];
1040
+ }
1041
+ exports.getAllLajiFormIdsDeeply = getAllLajiFormIdsDeeply;
1042
+ function removeLajiFormIds(formData, tree) {
1043
+ const itemOperator = (item) => immutableDelete(item, "_lajiFormId");
1044
+ return walkFormDataWithIdTree(formData, tree, itemOperator)[0];
1045
+ }
1046
+ exports.removeLajiFormIds = removeLajiFormIds;
1047
+ function findPointerForLajiFormId(tmpIdTree = {}, formData, lajiFormId) {
1048
+ if (tmpIdTree._hasId) {
1049
+ if (Array.isArray(formData)) {
1050
+ for (let idx in (formData || [])) {
1051
+ const item = formData[idx];
1052
+ if (exports.getUUID(item) === lajiFormId) {
1053
+ return "/" + idx;
1054
+ }
1055
+ }
1056
+ }
1057
+ else if (formData && exports.getUUID(formData) === lajiFormId) {
1058
+ return "";
1059
+ }
1060
+ }
1061
+ for (const k of Object.keys(tmpIdTree)) {
1062
+ if (exports.isObject(formData[k])) {
1063
+ const find = findPointerForLajiFormId(tmpIdTree[k], formData[k], lajiFormId);
1064
+ if (find !== undefined || find === "") {
1065
+ return `/${k}${find}`;
1066
+ }
1067
+ }
1068
+ else if (Array.isArray(formData[k])) {
1069
+ for (const i in formData[k]) {
1070
+ const item = formData[k][i];
1071
+ const find = findPointerForLajiFormId(tmpIdTree[k], item, lajiFormId);
1072
+ if (find !== undefined || find === "") {
1073
+ return `/${k}/${i}${find}`;
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+ return undefined;
1079
+ }
1080
+ exports.findPointerForLajiFormId = findPointerForLajiFormId;
1081
+ function highlightElem(elem) {
1082
+ if (!elem)
1083
+ return;
1084
+ if (elem.className.includes(" highlight-error-fire"))
1085
+ elem.className = elem.className.replace(" highlight-error-fire", "");
1086
+ window.setTimeout(() => elem.className = `${elem.className} highlight-error-fire`);
1087
+ }
1088
+ exports.highlightElem = highlightElem;
1089
+ function filteredErrors(errorSchema) {
1090
+ return Object.keys(errorSchema).reduce((_errorSchema, prop) => {
1091
+ if (prop === "__errors") {
1092
+ if (errorSchema.__errors.length) {
1093
+ _errorSchema.__errors = errorSchema.__errors;
1094
+ }
1095
+ return _errorSchema;
1096
+ }
1097
+ const errors = filteredErrors(errorSchema[prop]);
1098
+ if (Object.keys(errors).length) {
1099
+ _errorSchema[prop] = errors;
1100
+ }
1101
+ return _errorSchema;
1102
+ }, {});
1103
+ }
1104
+ exports.filteredErrors = filteredErrors;
1105
+ function constructTranslations(translations) {
1106
+ let dictionaries = { fi: {}, en: {}, sv: {} };
1107
+ for (let word in translations) {
1108
+ for (let lang in translations[word]) {
1109
+ const translation = translations[word][lang];
1110
+ dictionaries[lang][word] = decapitalizeFirstLetter(translation);
1111
+ dictionaries[lang][capitalizeFirstLetter(word)] = capitalizeFirstLetter(translation);
1112
+ }
1113
+ }
1114
+ return dictionaries;
1115
+ }
1116
+ exports.constructTranslations = constructTranslations;
1117
+ function getIdxWithOffset(idx, offsets, totalOffset) {
1118
+ let offset = idx in (offsets || {})
1119
+ ? (offsets || {})[idx]
1120
+ : totalOffset;
1121
+ return (offset || 0) + idx;
1122
+ }
1123
+ exports.getIdxWithOffset = getIdxWithOffset;
1124
+ function getIdxWithoutOffset(idx, offsets, totalOffset) {
1125
+ let offset = `_${idx}` in (offsets || {})
1126
+ ? (offsets || {})[`_${idx}`]
1127
+ : totalOffset;
1128
+ return idx - (offset || 0);
1129
+ }
1130
+ exports.getIdxWithoutOffset = getIdxWithoutOffset;
1131
+ /**
1132
+ * The indices of the formData that a component receives doesn't match the actual root formData indices,
1133
+ * if the data is sorted or has offsets. This returns the original index.
1134
+ */
1135
+ function getFormDataIndex(idx, uiSchema) {
1136
+ var _a;
1137
+ const { idxMap = {}, idxOffsets, totalOffset } = getUiOptions(uiSchema);
1138
+ const mappedIdx = (_a = idxMap[idx]) !== null && _a !== void 0 ? _a : idx;
1139
+ return getIdxWithOffset(mappedIdx, idxOffsets, totalOffset);
1140
+ }
1141
+ exports.getFormDataIndex = getFormDataIndex;
1142
+ /**
1143
+ * Given an index pointing to actual index in root formData, returns the index with sorting & offset applied.
1144
+ */
1145
+ function getReversedFormDataIndex(idx, uiSchema) {
1146
+ var _a;
1147
+ const { idxMap = {}, idxOffsets, totalOffset } = getUiOptions(uiSchema);
1148
+ const mappedIdx = (_a = idxMap["_" + idx]) !== null && _a !== void 0 ? _a : idx;
1149
+ return getIdxWithoutOffset(mappedIdx, idxOffsets, totalOffset);
1150
+ }
1151
+ exports.getReversedFormDataIndex = getReversedFormDataIndex;
1152
+ function toJSONPointer(s) {
1153
+ return s[0] !== "/"
1154
+ ? "/" + s
1155
+ : s;
1156
+ }
1157
+ exports.toJSONPointer = toJSONPointer;
1158
+ function getTitle(props, idx) {
1159
+ var _a, _b, _c, _d;
1160
+ let title = (_d = (_b = (_a = props.uiSchema) === null || _a === void 0 ? void 0 : _a["ui:title"]) !== null && _b !== void 0 ? _b : (_c = props.schema) === null || _c === void 0 ? void 0 : _c.title) !== null && _d !== void 0 ? _d : props.name;
1161
+ if (!(title === null || title === void 0 ? void 0 : title.includes("%{"))) {
1162
+ return title;
1163
+ }
1164
+ const formatters = {
1165
+ idx: typeof idx === "number" ? idx + 1 : undefined,
1166
+ title
1167
+ };
1168
+ return Object.keys(formatters).reduce((_title, key) => {
1169
+ [key, capitalizeFirstLetter(key)].map(key => `%{${key}}`).forEach(replacePattern => {
1170
+ while (_title.includes(replacePattern)) {
1171
+ const fn = replacePattern[2] === replacePattern[2].toLowerCase() ?
1172
+ decapitalizeFirstLetter : capitalizeFirstLetter;
1173
+ _title = _title.replace(replacePattern, fn(`${formatters[key]}`));
1174
+ }
1175
+ });
1176
+ return _title;
1177
+ }, title);
1178
+ }
1179
+ exports.getTitle = getTitle;
1180
+ const classNames = (...cs) => cs.filter(s => typeof s === "string").join(" ");
1181
+ exports.classNames = classNames;
1182
+ function translate(translations, key, params) {
1183
+ return Object.keys(params || {}).reduce((translated, param) => translated.replace(new RegExp(`%{${param}}`, "g"), (params === null || params === void 0 ? void 0 : params[param]) || ""), translations[key]);
1184
+ }
1185
+ exports.translate = translate;