@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
package/lib/utils.js DELETED
@@ -1,1191 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.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: _findNearestParentSchemaElemId,
249
- getSchemaElementById: _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
- const findNearestParentSchemaElemId = (elem) => {
330
- return _findNearestParentSchemaElemId(elem);
331
- };
332
- exports.findNearestParentSchemaElemId = findNearestParentSchemaElemId;
333
- const _getSchemaElementById = (id) => {
334
- return document.getElementById(`_laji-form_${id}`);
335
- };
336
- const getSchemaElementById = (id) => {
337
- return _getSchemaElementById(id);
338
- };
339
- exports.getSchemaElementById = getSchemaElementById;
340
- const _focusById = (context) => (id, focus = true) => {
341
- const elem = exports.getSchemaElementById(id);
342
- if (elem && document.body.contains(elem)) {
343
- const tabbableFields = getTabbableFields(elem);
344
- if (tabbableFields && tabbableFields.length) {
345
- focus && tabbableFields[0].focus();
346
- scrollIntoViewIfNeeded(elem, context.topOffset, context.bottomOffset);
347
- const rootContext = Context_1.default(context.contextId);
348
- rootContext.lastIdToFocus = id; // Mark for components that manipulate scroll positions
349
- rootContext.windowScrolled = getWindowScrolled();
350
- return true;
351
- }
352
- }
353
- return false;
354
- };
355
- const focusById = (context, id, focus) => _focusById(context)(id, focus);
356
- exports.focusById = focusById;
357
- const _focusAndScroll = (context) => (idToFocus, idToScroll, focus = true) => {
358
- const { contextId, topOffset, bottomOffset } = context;
359
- const _context = Context_1.default(contextId);
360
- if (idToFocus === undefined && idToScroll === undefined)
361
- return;
362
- if (idToFocus && !context.utils.focusById(getKeyHandlerTargetId(idToFocus, _context), focus))
363
- return false;
364
- if (idToScroll) {
365
- const elemToScroll = document.getElementById(getKeyHandlerTargetId(idToScroll, _context));
366
- const elemToFocus = exports.getSchemaElementById(getKeyHandlerTargetId(idToFocus, _context));
367
- if (!elemToScroll || !elemToFocus) {
368
- return end();
369
- }
370
- const wouldScrollTo = getScrollPositionForScrollIntoViewIfNeeded(elemToScroll, topOffset, bottomOffset);
371
- const scrollAmount = wouldScrollTo - getWindowScrolled();
372
- const { top } = elemToFocus.getBoundingClientRect();
373
- const viewTopDistanceFromTop = top - scrollAmount;
374
- // Don't scroll if scrolling would hide focused elem top.
375
- if (viewTopDistanceFromTop < topOffset) {
376
- return end();
377
- }
378
- else {
379
- scrollIntoViewIfNeeded(elemToScroll, topOffset, bottomOffset);
380
- }
381
- }
382
- return end();
383
- function end() {
384
- _context.lastIdToScroll = idToScroll;
385
- _context.lastIdToFocus = idToFocus;
386
- _context.windowScrolled = getWindowScrolled();
387
- return true;
388
- }
389
- };
390
- const focusAndScroll = (context, idToFocus, idToScroll, focus) => _focusAndScroll(context)(idToFocus, idToScroll, focus);
391
- exports.focusAndScroll = focusAndScroll;
392
- const _shouldSyncScroll = (context) => () => {
393
- return Context_1.default(context.contextId).windowScrolled === getWindowScrolled();
394
- };
395
- const shouldSyncScroll = (context) => _shouldSyncScroll(context)();
396
- exports.shouldSyncScroll = shouldSyncScroll;
397
- const _syncScroll = (context) => (force = false) => {
398
- if (force || exports.shouldSyncScroll(context)) {
399
- const { lastIdToFocus, lastIdToScroll } = Context_1.default(context.contextId);
400
- exports.focusAndScroll(context, lastIdToFocus, lastIdToScroll, false);
401
- }
402
- };
403
- exports._syncScroll = _syncScroll;
404
- const syncScroll = (context, force) => exports._syncScroll(context)(force);
405
- exports.syncScroll = syncScroll;
406
- const filterLajiFormId = (item) => {
407
- if (item && item._lajiFormId) {
408
- const { _lajiFormId } = item, _item = __rest(item, ["_lajiFormId"]); // eslint-disable-line @typescript-eslint/no-unused-vars
409
- item = _item;
410
- }
411
- return item;
412
- };
413
- exports.filterLajiFormId = filterLajiFormId;
414
- const filterItemId = (item) => {
415
- if (item && (item._lajiFormId || item.id)) {
416
- const { _lajiFormId, id } = item, _item = __rest(item, ["_lajiFormId", "id"]); // eslint-disable-line @typescript-eslint/no-unused-vars
417
- item = _item;
418
- }
419
- return item;
420
- };
421
- exports.filterItemId = filterItemId;
422
- const _filterItemIdsDeeply = (context) => (item, idSchemaId) => {
423
- const tmpIdTree = context.services.ids.getRelativeTmpIdTree(idSchemaId);
424
- let [_item] = walkFormDataWithIdTree(item, tmpIdTree, exports.filterItemId);
425
- return _item;
426
- };
427
- const filterItemIdsDeeply = (item, context, idSchemaId) => _filterItemIdsDeeply(context)(item, idSchemaId);
428
- exports.filterItemIdsDeeply = filterItemIdsDeeply;
429
- const _formDataIsEmpty = (context) => (props) => {
430
- const tmpIdTree = context.services.ids.getRelativeTmpIdTree(props.idSchema.$id);
431
- let [item] = walkFormDataWithIdTree(props.formData, tmpIdTree, exports.filterItemId);
432
- return deepEquals(item, getDefaultFormState(props.schema, undefined, props.registry.rootSchema));
433
- };
434
- const formDataIsEmpty = (props, context) => _formDataIsEmpty(context)(props);
435
- exports.formDataIsEmpty = formDataIsEmpty;
436
- const _formDataEquals = (context) => (f1, f2, id) => {
437
- const tmpIdTree = context.services.ids.getRelativeTmpIdTree(id);
438
- const [_f1, _f2] = [f1, f2].map(i => walkFormDataWithIdTree(i, tmpIdTree, exports.filterItemId)[0]);
439
- return deepEquals(_f1, _f2);
440
- };
441
- const formDataEquals = (f1, f2, context, id) => {
442
- return _formDataEquals(context)(f1, f2, id);
443
- };
444
- exports.formDataEquals = formDataEquals;
445
- const _keyboardClick = ({ contextId }) => (fn) => {
446
- return (e) => {
447
- var _a, _b;
448
- let keys = [" ", "Enter"];
449
- if ((_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.matches) === null || _b === void 0 ? void 0 : _b.call(_a, tabbableSelectorsQuery)) {
450
- const { shortcuts } = Context_1.default(contextId);
451
- keys = keys.filter(k => !(shortcuts === null || shortcuts === void 0 ? void 0 : shortcuts[k]));
452
- }
453
- if (keys.every(k => e.key !== k)) {
454
- return;
455
- }
456
- e.preventDefault();
457
- e.stopPropagation();
458
- fn(e);
459
- };
460
- };
461
- const keyboardClick = (fn, context) => {
462
- return _keyboardClick(context)(fn);
463
- };
464
- exports.keyboardClick = keyboardClick;
465
- function getNestedTailUiSchema(uiSchema) {
466
- while (uiSchema && uiSchema.uiSchema) {
467
- uiSchema = uiSchema.uiSchema;
468
- }
469
- return uiSchema;
470
- }
471
- exports.getNestedTailUiSchema = getNestedTailUiSchema;
472
- function updateTailUiSchema(uiSchema, updateObject) {
473
- let tailPointer = {};
474
- let root = tailPointer;
475
- let uiSchemaPointer = uiSchema;
476
- while (uiSchemaPointer.uiSchema) {
477
- uiSchemaPointer = uiSchemaPointer.uiSchema;
478
- tailPointer.uiSchema = {};
479
- if (uiSchemaPointer.uiSchema)
480
- tailPointer = tailPointer.uiSchema;
481
- }
482
- tailPointer.uiSchema = updateObject;
483
- return immutability_helper_1.default(uiSchema, root);
484
- }
485
- exports.updateTailUiSchema = updateTailUiSchema;
486
- function getNestedUiFieldsList(uiSchema) {
487
- const list = [];
488
- while (uiSchema.uiSchema && uiSchema.uiSchema["ui:field"]) {
489
- list.push(uiSchema.uiSchema["ui:field"]);
490
- uiSchema = uiSchema.uiSchema;
491
- }
492
- return list;
493
- }
494
- exports.getNestedUiFieldsList = getNestedUiFieldsList;
495
- function getBootstrapCols(width) {
496
- return ["lg", "md", "sm", "xs"].reduce((o, c) => {
497
- o[c] = width;
498
- return o;
499
- }, {});
500
- }
501
- exports.getBootstrapCols = getBootstrapCols;
502
- function isDescendant(parent, child) {
503
- let node = child.parentNode;
504
- while (node != null) {
505
- if (node == parent) {
506
- return true;
507
- }
508
- node = node.parentNode;
509
- }
510
- return false;
511
- }
512
- exports.isDescendant = isDescendant;
513
- function getKeyHandlerTargetId(target = "", context, formData) {
514
- var _a;
515
- while (target.match(/%\{([^{}]*)\}/)) {
516
- const path = ((_a = /%\{([^{}]*)\}/.exec(target)) === null || _a === void 0 ? void 0 : _a[1]) || "";
517
- if (!path.startsWith("context") && !path.startsWith("formData"))
518
- throw Error("Should evaluate 'context' or 'formData'");
519
- target = target.replace(`%{${path}}`, eval(path));
520
- }
521
- return target;
522
- }
523
- exports.getKeyHandlerTargetId = getKeyHandlerTargetId;
524
- function capitalizeFirstLetter(string) {
525
- return string.charAt(0).toUpperCase() + string.slice(1);
526
- }
527
- exports.capitalizeFirstLetter = capitalizeFirstLetter;
528
- function decapitalizeFirstLetter(string) {
529
- return string.charAt(0).toLowerCase() + string.slice(1);
530
- }
531
- exports.decapitalizeFirstLetter = decapitalizeFirstLetter;
532
- function stringifyKeyCombo(keyCombo = "") {
533
- return keyCombo.split("+").map(key => {
534
- if (key === " ")
535
- key = "space";
536
- return capitalizeFirstLetter(key);
537
- }).join(" + ");
538
- }
539
- exports.stringifyKeyCombo = stringifyKeyCombo;
540
- function canAdd(props) {
541
- return (!("canAdd" in props) || props.canAdd) && getUiOptions(props.uiSchema).canAdd !== false;
542
- }
543
- exports.canAdd = canAdd;
544
- function bsSizeToPixels(bsSize) {
545
- switch (bsSize) {
546
- case "lg":
547
- return 1200;
548
- case "md":
549
- return 992;
550
- case "sm":
551
- return 768;
552
- case "xs":
553
- return 576;
554
- default:
555
- throw new Error(`Unknown bootstrap size ${bsSize}. Should be one of 'lg', 'md', 'sm' or 'xs'`);
556
- }
557
- }
558
- exports.bsSizeToPixels = bsSizeToPixels;
559
- function pixelsToBsSize(pixels) {
560
- if (pixels < 576) {
561
- return "xs";
562
- }
563
- else if (pixels < 768) {
564
- return "sm";
565
- }
566
- else if (pixels < 992) {
567
- return "md";
568
- }
569
- else if (pixels < 1200) {
570
- return "lg";
571
- }
572
- return "";
573
- }
574
- exports.pixelsToBsSize = pixelsToBsSize;
575
- function applyFunction(props) {
576
- let { "ui:functions": functions, "ui:childFunctions": childFunctions } = (props.uiSchema || {});
577
- const objectOrArrayAsArray = (item) => (item ?
578
- (Array.isArray(item) ?
579
- item :
580
- [item]) :
581
- []);
582
- if (childFunctions) {
583
- functions = [
584
- { "ui:field": "UiFieldMapperArrayField", "ui:options": { functions: objectOrArrayAsArray(childFunctions) } },
585
- ...objectOrArrayAsArray(functions)
586
- ];
587
- }
588
- if (!functions)
589
- return props;
590
- const computedProps = ((Array.isArray(functions)) ? functions : [functions]).reduce((_props, { "ui:field": uiField, "ui:options": uiOptions }) => {
591
- _props = Object.assign(Object.assign({}, _props), { uiSchema: Object.assign(Object.assign({}, _props.uiSchema), { "ui:field": uiField, "ui:options": uiOptions, uiSchema: undefined }) });
592
- const { state = {} } = new props.registry.fields[uiField](_props);
593
- return Object.assign(Object.assign({}, _props), state);
594
- }, Object.assign(Object.assign({}, props), { formContext: props.registry.formContext }));
595
- 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 }) });
596
- }
597
- exports.applyFunction = applyFunction;
598
- function getWindowScrolled() {
599
- return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
600
- }
601
- exports.getWindowScrolled = getWindowScrolled;
602
- function getScrollPositionForScrollIntoViewIfNeeded(elem, topOffset = 0, bottomOffset = 0) {
603
- if (!elem)
604
- return getWindowScrolled();
605
- const rect = elem.getBoundingClientRect();
606
- const html = document.documentElement;
607
- const height = elem.scrollHeight;
608
- const inView = (rect.top >= topOffset &&
609
- rect.bottom <= (window.innerHeight || html.clientHeight) - bottomOffset);
610
- const elemTopDistFromViewportTop = rect.top;
611
- const viewportHeight = (window.innerHeight || html.clientHeight);
612
- const elemBottomDistFromViewportBottom = -(elemTopDistFromViewportTop + height - viewportHeight);
613
- const pageScrolled = getWindowScrolled();
614
- if (inView)
615
- return pageScrolled;
616
- // Priorize scrolling the top of the element into view if showing the bottom would obscure the top of the element.
617
- if (pageScrolled + elemTopDistFromViewportTop - topOffset > elemTopDistFromViewportTop) {
618
- return pageScrolled + elemTopDistFromViewportTop - topOffset;
619
- }
620
- else {
621
- return pageScrolled - elemBottomDistFromViewportBottom + bottomOffset;
622
- }
623
- }
624
- exports.getScrollPositionForScrollIntoViewIfNeeded = getScrollPositionForScrollIntoViewIfNeeded;
625
- function scrollIntoViewIfNeeded(elem, topOffset = 0, bottomOffset = 0) {
626
- window.scrollTo(0, getScrollPositionForScrollIntoViewIfNeeded(elem, topOffset, bottomOffset));
627
- }
628
- exports.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded;
629
- function filter(properties, filter, filterType = "blacklist", getValue) {
630
- const filterDictionary = {};
631
- filter.forEach(_enum => { filterDictionary[_enum] = true; });
632
- const filterFn = (item) => {
633
- const value = getValue ? getValue(item) : item;
634
- return filterDictionary[value];
635
- };
636
- return properties.filter(filterType === "whitelist" ? filterFn : e => !filterFn(e));
637
- }
638
- exports.filter = filter;
639
- function updateSafelyWithJSONPath(obj, value, path, immutably, createNew) {
640
- 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");
641
- return updateSafelyWithJSONPointer(obj, value, path, immutably, createNew);
642
- }
643
- exports.updateSafelyWithJSONPath = updateSafelyWithJSONPath;
644
- function updateSafelyWithJSONPointer(obj, value, path, immutably = true, createNew = () => ({})) {
645
- if (path === "/") {
646
- return value;
647
- }
648
- if (!immutably) {
649
- const splitted = path.split("/").filter(s => !isEmptyString(s));
650
- splitted.reduce((o, split, i) => {
651
- if (i === splitted.length - 1) {
652
- o[split] = value;
653
- return;
654
- }
655
- if (!o[split]) {
656
- o[split] = createNew(o, split);
657
- }
658
- return o[split];
659
- }, obj);
660
- return obj;
661
- }
662
- let injectionTarget = false;
663
- try {
664
- injectionTarget = parseJSONPointer(obj, path);
665
- }
666
- catch (e) {
667
- injectionTarget = makePath(injectionTarget);
668
- }
669
- // If path for injection doesn't exist, we create it immutably.
670
- if (!injectionTarget) {
671
- injectionTarget = makePath(injectionTarget);
672
- }
673
- const updateObject = getUpdateObjectFromJSONPointer(path, { $set: value });
674
- return immutability_helper_1.default(obj, updateObject);
675
- function makePath(injectionTarget) {
676
- const splitPath = path.split("/").filter(s => !isEmptyString(s));
677
- let _splitPath = "";
678
- splitPath.reduce((o, split) => {
679
- _splitPath += `/${split}`;
680
- if (!o[split]) {
681
- obj = immutability_helper_1.default(obj, getUpdateObjectFromJSONPointer(_splitPath, { $set: createNew(obj, _splitPath, o, split) }));
682
- }
683
- const next = parseJSONPointer(obj, _splitPath);
684
- injectionTarget = next;
685
- return next;
686
- }, obj);
687
- return injectionTarget;
688
- }
689
- }
690
- exports.updateSafelyWithJSONPointer = updateSafelyWithJSONPointer;
691
- function injectButtons(uiSchema, buttons, buttonsPath) {
692
- const existingButtons = parseJSONPointer(uiSchema, `${buttonsPath}/ui:options/buttons`);
693
- return updateSafelyWithJSONPointer(uiSchema, existingButtons ? [...existingButtons, ...buttons] : buttons, `${buttonsPath}/ui:options/buttons`);
694
- }
695
- exports.injectButtons = injectButtons;
696
- function dictionarify(array, getKey, getValue) {
697
- return array.reduce((o, k) => {
698
- o[getKey ? getKey(k) : k] = getValue ? getValue(k) : true;
699
- return o;
700
- }, {});
701
- }
702
- exports.dictionarify = dictionarify;
703
- const tableFormatters = {
704
- unknownTaxon: (item, formatted, options, parentProps = {}) => (isEmptyString(item) || (parentProps.formData || {})[options.idField])
705
- ? formatted
706
- : (React.createElement(ReactContext_1.default.Consumer, null, ({ theme: { Glyphicon } }) => React.createElement("span", null,
707
- formatted,
708
- " ",
709
- React.createElement("span", { className: "text-warning" },
710
- React.createElement(Glyphicon, { glyph: "warning-sign" })))))
711
- };
712
- function formatValue(props, _formatter, parentProps) {
713
- let { formData, uiSchema = {}, schema, registry } = props;
714
- let formatter = undefined;
715
- let formatterComponent = undefined;
716
- if (uiSchema["ui:widget"])
717
- formatterComponent = registry.widgets[uiSchema["ui:widget"]];
718
- else if (schema.type === "boolean")
719
- formatterComponent = registry.widgets.CheckboxWidget;
720
- else if (uiSchema["ui:field"])
721
- formatterComponent = registry.fields[uiSchema["ui:field"]];
722
- if (formatterComponent && formatterComponent.prototype && formatterComponent.prototype.formatValue) {
723
- formatter = formatterComponent.prototype.formatValue;
724
- }
725
- else if (formatterComponent && formatterComponent.prototype && formatterComponent.prototype.__proto__ && formatterComponent.prototype.__proto__.formatValue) {
726
- formatter = formatterComponent.prototype.__proto__.formatValue;
727
- }
728
- const arrayJoiner = (value, i, length, separator = "; ") => {
729
- const comma = React.createElement(React.Fragment, { key: `_${i}` }, separator);
730
- return i < length - 1
731
- ? [value, comma] : [value];
732
- };
733
- let formatted = formData;
734
- if (formatter) {
735
- formatted = formatter(formData, getUiOptions(uiSchema), props, parentProps);
736
- }
737
- else if (isEmptyString(formData)) {
738
- formatted = "";
739
- }
740
- else if (isMultiSelect(schema)) {
741
- formatted = formData.map((_val) => schema.items.oneOf.find((one) => one.const === _val).title).join(", ");
742
- }
743
- else if (schema.type === "object") {
744
- const keys = Object.keys(formData);
745
- return keys.map((_col, i) => {
746
- const child = React.createElement(React.Fragment, { key: _col }, formatValue(Object.assign(Object.assign({}, props), { schema: schema.properties[_col], uiSchema: uiSchema[_col], formData: formData[_col] })));
747
- return arrayJoiner(child, i, keys.length);
748
- });
749
- }
750
- else if (schema.type === "array") {
751
- formatted = React.createElement("span", { className: "single-active-array-table-array" }, formData.map((_val, i) => {
752
- const child = React.createElement(React.Fragment, { key: i }, formatValue(Object.assign(Object.assign({}, props), { schema: props.schema.items, uiSchema: uiSchema.items, formData: _val })));
753
- return arrayJoiner(child, i, formData.length, "; ");
754
- }));
755
- }
756
- else if (isSelect(schema)) {
757
- formatted = isEmptyString(formData) ? formData : schema.oneOf.find((one) => one.const === formData).title;
758
- }
759
- else if (schema.type === "boolean") {
760
- formatted = props.formContext.translations[formData ? "yes" : "no"];
761
- }
762
- if (_formatter) {
763
- formatted = tableFormatters[_formatter.formatter](formData, formatted, _formatter, parentProps);
764
- }
765
- return formatted;
766
- }
767
- exports.formatValue = formatValue;
768
- const formatErrorMessage = (msg) => msg.replace(/^\[.*\]/, "");
769
- exports.formatErrorMessage = formatErrorMessage;
770
- function checkRules(rules, props, cache, prop = "formData") {
771
- const passes = (Array.isArray(rules) ? rules : [rules]).every((rule, idx) => {
772
- let passes;
773
- // BW compatibility for old string rule
774
- if (rule === "isAdmin") {
775
- rule = { rule: "isAdmin" };
776
- }
777
- else if (rule === "isEdit") {
778
- rule = { rule: "isEdit" };
779
- }
780
- const { field, regexp, valueIn, valueIncludes, valueLengthLessThan, rule: _rule } = rule;
781
- if (_rule) {
782
- if (_rule === "isAdmin") {
783
- passes = props.formContext.uiSchemaContext.isAdmin;
784
- }
785
- else if (_rule === "isEdit") {
786
- passes = props.formContext.uiSchemaContext.isEdit;
787
- }
788
- }
789
- else {
790
- let value = parseJSONPointer(props[prop] || {}, field);
791
- if (value === undefined)
792
- value = "";
793
- if (regexp) {
794
- passes = `${value}`.match(new RegExp(regexp));
795
- }
796
- else if (valueIn) {
797
- if (cache) {
798
- if (!cache[idx]) {
799
- cache[idx] = dictionarify(valueIn);
800
- }
801
- passes = cache[idx][value];
802
- }
803
- else {
804
- passes = dictionarify(valueIn)[value];
805
- }
806
- }
807
- else if (valueIncludes !== undefined) {
808
- passes = value.includes(valueIncludes);
809
- }
810
- else if (valueLengthLessThan !== undefined) {
811
- passes = value.length < valueLengthLessThan;
812
- }
813
- }
814
- return rule.complement ? !passes : passes;
815
- });
816
- return cache ? { passes, cache } : passes;
817
- }
818
- exports.checkRules = checkRules;
819
- function checkArrayRules(rules, props, idx, cache, prop = "formData") {
820
- const arrayRules = (Array.isArray(rules) ? rules : [rules]).filter(rule => ["isLast", "idx"].some(r => r in rule));
821
- const passes = arrayRules.every(rule => {
822
- let passes;
823
- if ("isLast" in rule) {
824
- passes = (idx === props.formData.length - 1) === rule.isLast;
825
- }
826
- else if ("idx" in rule) {
827
- passes = idx === rule.idx;
828
- }
829
- if (passes !== undefined) {
830
- return rule.complement ? !passes : passes;
831
- }
832
- return true;
833
- });
834
- const nonArrayRules = (Array.isArray(rules) ? rules : [rules]).filter(rule => !arrayRules.includes(rule));
835
- if (nonArrayRules.length) {
836
- const nonArrayRulesCheck = checkRules(nonArrayRules, Object.assign(Object.assign({}, props), { formData: props.formData[idx] }), cache, prop);
837
- const allPass = passes && cache ? nonArrayRulesCheck.passes : nonArrayRulesCheck;
838
- if (cache) {
839
- return { passes: allPass, cache };
840
- }
841
- else {
842
- return allPass;
843
- }
844
- }
845
- else {
846
- return cache ? { cache, passes } : passes;
847
- }
848
- }
849
- exports.checkArrayRules = checkArrayRules;
850
- function bringRemoteFormData(formData, formContext) {
851
- if (formContext.formDataTransformers) {
852
- return formContext.formDataTransformers.reduce((formData, { "ui:field": uiField, props: fieldProps }) => {
853
- const { state = {} } = new fieldProps.registry.fields[uiField](Object.assign(Object.assign({}, fieldProps), { formData }));
854
- return state.formData;
855
- }, formData);
856
- }
857
- else {
858
- return formData;
859
- }
860
- }
861
- exports.bringRemoteFormData = bringRemoteFormData;
862
- function triggerParentComponent(eventName, e, props) {
863
- if (props && props[eventName]) {
864
- e.persist && e.persist();
865
- props[eventName](e);
866
- }
867
- }
868
- exports.triggerParentComponent = triggerParentComponent;
869
- function parseSchemaFromFormDataPointer(schema, pointer) {
870
- const splits = pointer.split("/").filter(s => !isEmptyString(s));
871
- const value = splits.reduce((o, s) => {
872
- if (!isNaN(parseInt(s))) {
873
- return o.items;
874
- }
875
- if (o.type === "array" && o.items.properties[s])
876
- return o.items.properties[s];
877
- if (o.type === "array")
878
- return o.items;
879
- return o.properties[s];
880
- }, schema);
881
- return value;
882
- }
883
- exports.parseSchemaFromFormDataPointer = parseSchemaFromFormDataPointer;
884
- function parseUiSchemaFromFormDataPointer(uiSchema, pointer) {
885
- const splits = pointer.split("/").filter(s => !isEmptyString(s));
886
- return splits.reduce((o, s) => {
887
- if (!isNaN(parseInt(s))) {
888
- return o.items;
889
- }
890
- if (o && o.items)
891
- return o.items[s];
892
- return o ? o[s] : {};
893
- }, uiSchema);
894
- }
895
- exports.parseUiSchemaFromFormDataPointer = parseUiSchemaFromFormDataPointer;
896
- function checkJSONPointer(obj, pointer) {
897
- if (!obj)
898
- return false;
899
- const splits = pointer.split("/").filter(s => !isEmptyString(s));
900
- try {
901
- let _pointer = obj;
902
- return splits.every(split => {
903
- const exists = split in _pointer;
904
- _pointer = _pointer[split];
905
- return exists;
906
- });
907
- }
908
- catch (e) {
909
- return false;
910
- }
911
- }
912
- exports.checkJSONPointer = checkJSONPointer;
913
- const JSONPointerToId = (fieldName) => fieldName[0] === "/" ? fieldName.replace(/(?!^)\//g, "_").substr(1) : fieldName;
914
- exports.JSONPointerToId = JSONPointerToId;
915
- const idSchemaIdToJSONPointer = (id) => id.replace(/root_|_/g, "/");
916
- exports.idSchemaIdToJSONPointer = idSchemaIdToJSONPointer;
917
- function schemaJSONPointer(schema, JSONPointer) {
918
- if (JSONPointer[0] !== "/") {
919
- JSONPointer = `/${JSONPointer}`;
920
- }
921
- let schemaPointer = schema;
922
- return JSONPointer.split("/").filter(s => !isEmptyString(s)).reduce((path, s) => {
923
- if (schemaPointer[s]) {
924
- schemaPointer = schemaPointer[s];
925
- return `${path}/${s}`;
926
- }
927
- else if (!isNaN(+s) && schemaPointer.items) {
928
- schemaPointer = schemaPointer.items;
929
- return `${path}/items`;
930
- }
931
- else if (schemaPointer.properties && schemaPointer.properties[s]) {
932
- schemaPointer = schemaPointer.properties[s];
933
- return `${path}/properties/${s}`;
934
- }
935
- return undefined;
936
- }, "");
937
- }
938
- exports.schemaJSONPointer = schemaJSONPointer;
939
- function uiSchemaJSONPointer(schema, JSONPointer) {
940
- if (JSONPointer[0] !== "/")
941
- return JSONPointer;
942
- let schemaPointer = schema;
943
- return JSONPointer.split("/").filter(s => !isEmptyString(s)).reduce((path, s) => {
944
- if (schemaPointer[s]) {
945
- schemaPointer = schemaPointer[s];
946
- return `${path}/${s}`;
947
- }
948
- else if (schemaPointer.properties && schemaPointer.properties[s]) {
949
- schemaPointer = schemaPointer.properties[s];
950
- return `${path}/${s}`;
951
- }
952
- else if (schemaPointer.items.properties && schemaPointer.items.properties[s]) {
953
- schemaPointer = schemaPointer.items.properties[s];
954
- return `${path}/items/${s}`;
955
- }
956
- else if (!isNaN(+s) && schemaPointer.items) {
957
- schemaPointer = schemaPointer.items;
958
- return `${path}/items`;
959
- }
960
- return undefined;
961
- }, "");
962
- }
963
- exports.uiSchemaJSONPointer = uiSchemaJSONPointer;
964
- function updateFormDataWithJSONPointer(schemaProps, value, path) {
965
- if (path === "/") {
966
- return value;
967
- }
968
- return updateSafelyWithJSONPointer(schemaProps.formData, value, path, !!"immutably", (__formData, _path) => {
969
- const schemaPointer = schemaJSONPointer(schemaProps.schema, _path);
970
- if (schemaPointer === undefined) {
971
- throw new Error(`Bad JSON Schema pointer '${schemaPointer}!`);
972
- }
973
- const _schema = parseJSONPointer(schemaProps.schema, schemaPointer);
974
- let _default = getDefaultFormState(_schema, undefined, schemaProps.registry.rootSchema);
975
- if (!_default && _schema.type === "array") {
976
- return [];
977
- }
978
- return _default;
979
- });
980
- }
981
- exports.updateFormDataWithJSONPointer = updateFormDataWithJSONPointer;
982
- let uuid = 0;
983
- const assignUUID = (item, immutably = false) => {
984
- if (exports.isObject(item) && !item.id && !item._lajiFormId) {
985
- uuid++;
986
- if (immutably) {
987
- return Object.assign(Object.assign({}, item), { _lajiFormId: uuid });
988
- }
989
- else {
990
- item._lajiFormId = uuid;
991
- return item;
992
- }
993
- }
994
- return item;
995
- };
996
- exports.assignUUID = assignUUID;
997
- const getUUID = (item) => item ? (item.id || item._lajiFormId) : undefined;
998
- exports.getUUID = getUUID;
999
- /**
1000
- * Return item UUID or the parent UUID
1001
- **/
1002
- const getFieldUUID = (props) => exports.getUUID(props.formData) || props.formContext._parentLajiFormId || "root";
1003
- exports.getFieldUUID = getFieldUUID;
1004
- function walkFormDataWithIdTree(_formData, tree, itemOperator) {
1005
- const ids = {};
1006
- const walk = (_formData, tree) => {
1007
- if (!tree)
1008
- return _formData;
1009
- const { _hasId } = tree, _tree = __rest(tree, ["_hasId"]);
1010
- if (_hasId && exports.isObject(_formData)) {
1011
- _formData = itemOperator ? itemOperator(_formData) : _formData;
1012
- }
1013
- if (Object.keys(_tree).length && exports.isObject(_formData)) {
1014
- return Object.keys(_formData).reduce((f, k) => {
1015
- if (tree[k]) {
1016
- f[k] = walk(_formData[k], tree[k]);
1017
- }
1018
- else {
1019
- f[k] = _formData[k];
1020
- }
1021
- return f;
1022
- }, {});
1023
- }
1024
- else if (tree && Array.isArray(_formData)) {
1025
- return _formData.map(item => {
1026
- item = walk(item, tree);
1027
- item = itemOperator ? itemOperator(item) : item;
1028
- if (exports.getUUID(item)) {
1029
- ids[exports.getUUID(item)] = true;
1030
- }
1031
- return item;
1032
- });
1033
- }
1034
- return _formData;
1035
- };
1036
- const formData = walk(_formData, tree);
1037
- return [formData, ids];
1038
- }
1039
- function addLajiFormIds(_formData, tree, immutably = true) {
1040
- const itemOperator = (item) => exports.assignUUID(item, immutably);
1041
- return walkFormDataWithIdTree(_formData, tree, itemOperator);
1042
- }
1043
- exports.addLajiFormIds = addLajiFormIds;
1044
- function getAllLajiFormIdsDeeply(_formData, tree) {
1045
- return walkFormDataWithIdTree(_formData, tree)[1];
1046
- }
1047
- exports.getAllLajiFormIdsDeeply = getAllLajiFormIdsDeeply;
1048
- function removeLajiFormIds(formData, tree) {
1049
- const itemOperator = (item) => immutableDelete(item, "_lajiFormId");
1050
- return walkFormDataWithIdTree(formData, tree, itemOperator)[0];
1051
- }
1052
- exports.removeLajiFormIds = removeLajiFormIds;
1053
- function findPointerForLajiFormId(tmpIdTree = {}, formData, lajiFormId) {
1054
- if (tmpIdTree._hasId) {
1055
- if (Array.isArray(formData)) {
1056
- for (let idx in (formData || [])) {
1057
- const item = formData[idx];
1058
- if (exports.getUUID(item) === lajiFormId) {
1059
- return "/" + idx;
1060
- }
1061
- }
1062
- }
1063
- else if (formData && exports.getUUID(formData) === lajiFormId) {
1064
- return "";
1065
- }
1066
- }
1067
- for (const k of Object.keys(tmpIdTree)) {
1068
- if (exports.isObject(formData[k])) {
1069
- const find = findPointerForLajiFormId(tmpIdTree[k], formData[k], lajiFormId);
1070
- if (find !== undefined || find === "") {
1071
- return `/${k}${find}`;
1072
- }
1073
- }
1074
- else if (Array.isArray(formData[k])) {
1075
- for (const i in formData[k]) {
1076
- const item = formData[k][i];
1077
- const find = findPointerForLajiFormId(tmpIdTree[k], item, lajiFormId);
1078
- if (find !== undefined || find === "") {
1079
- return `/${k}/${i}${find}`;
1080
- }
1081
- }
1082
- }
1083
- }
1084
- return undefined;
1085
- }
1086
- exports.findPointerForLajiFormId = findPointerForLajiFormId;
1087
- function highlightElem(elem) {
1088
- if (!elem)
1089
- return;
1090
- if (elem.className.includes(" highlight-error-fire"))
1091
- elem.className = elem.className.replace(" highlight-error-fire", "");
1092
- window.setTimeout(() => elem.className = `${elem.className} highlight-error-fire`);
1093
- }
1094
- exports.highlightElem = highlightElem;
1095
- function filteredErrors(errorSchema) {
1096
- return Object.keys(errorSchema).reduce((_errorSchema, prop) => {
1097
- if (prop === "__errors") {
1098
- if (errorSchema.__errors.length) {
1099
- _errorSchema.__errors = errorSchema.__errors;
1100
- }
1101
- return _errorSchema;
1102
- }
1103
- const errors = filteredErrors(errorSchema[prop]);
1104
- if (Object.keys(errors).length) {
1105
- _errorSchema[prop] = errors;
1106
- }
1107
- return _errorSchema;
1108
- }, {});
1109
- }
1110
- exports.filteredErrors = filteredErrors;
1111
- function constructTranslations(translations) {
1112
- let dictionaries = { fi: {}, en: {}, sv: {} };
1113
- for (let word in translations) {
1114
- for (let lang in translations[word]) {
1115
- const translation = translations[word][lang];
1116
- dictionaries[lang][word] = decapitalizeFirstLetter(translation);
1117
- dictionaries[lang][capitalizeFirstLetter(word)] = capitalizeFirstLetter(translation);
1118
- }
1119
- }
1120
- return dictionaries;
1121
- }
1122
- exports.constructTranslations = constructTranslations;
1123
- function getIdxWithOffset(idx, offsets, totalOffset) {
1124
- let offset = idx in (offsets || {})
1125
- ? (offsets || {})[idx]
1126
- : totalOffset;
1127
- return (offset || 0) + idx;
1128
- }
1129
- exports.getIdxWithOffset = getIdxWithOffset;
1130
- function getIdxWithoutOffset(idx, offsets, totalOffset) {
1131
- let offset = `_${idx}` in (offsets || {})
1132
- ? (offsets || {})[`_${idx}`]
1133
- : totalOffset;
1134
- return idx - (offset || 0);
1135
- }
1136
- exports.getIdxWithoutOffset = getIdxWithoutOffset;
1137
- /**
1138
- * The indices of the formData that a component receives doesn't match the actual root formData indices,
1139
- * if the data is sorted or has offsets. This returns the original index.
1140
- */
1141
- function getFormDataIndex(idx, uiSchema) {
1142
- var _a;
1143
- const { idxMap = {}, idxOffsets, totalOffset } = getUiOptions(uiSchema);
1144
- const mappedIdx = (_a = idxMap[idx]) !== null && _a !== void 0 ? _a : idx;
1145
- return getIdxWithOffset(mappedIdx, idxOffsets, totalOffset);
1146
- }
1147
- exports.getFormDataIndex = getFormDataIndex;
1148
- /**
1149
- * Given an index pointing to actual index in root formData, returns the index with sorting & offset applied.
1150
- */
1151
- function getReversedFormDataIndex(idx, uiSchema) {
1152
- var _a;
1153
- const { idxMap = {}, idxOffsets, totalOffset } = getUiOptions(uiSchema);
1154
- const mappedIdx = (_a = idxMap["_" + idx]) !== null && _a !== void 0 ? _a : idx;
1155
- return getIdxWithoutOffset(mappedIdx, idxOffsets, totalOffset);
1156
- }
1157
- exports.getReversedFormDataIndex = getReversedFormDataIndex;
1158
- function toJSONPointer(s) {
1159
- return s[0] !== "/"
1160
- ? "/" + s
1161
- : s;
1162
- }
1163
- exports.toJSONPointer = toJSONPointer;
1164
- function getTitle(props, idx) {
1165
- var _a, _b, _c, _d;
1166
- 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;
1167
- if (!(title === null || title === void 0 ? void 0 : title.includes("%{"))) {
1168
- return title;
1169
- }
1170
- const formatters = {
1171
- idx: typeof idx === "number" ? idx + 1 : undefined,
1172
- title
1173
- };
1174
- return Object.keys(formatters).reduce((_title, key) => {
1175
- [key, capitalizeFirstLetter(key)].map(key => `%{${key}}`).forEach(replacePattern => {
1176
- while (_title.includes(replacePattern)) {
1177
- const fn = replacePattern[2] === replacePattern[2].toLowerCase() ?
1178
- decapitalizeFirstLetter : capitalizeFirstLetter;
1179
- _title = _title.replace(replacePattern, fn(`${formatters[key]}`));
1180
- }
1181
- });
1182
- return _title;
1183
- }, title);
1184
- }
1185
- exports.getTitle = getTitle;
1186
- const classNames = (...cs) => cs.filter(s => typeof s === "string").join(" ");
1187
- exports.classNames = classNames;
1188
- function translate(translations, key, params) {
1189
- return Object.keys(params || {}).reduce((translated, param) => translated.replace(new RegExp(`%{${param}}`, "g"), (params === null || params === void 0 ? void 0 : params[param]) || ""), translations[key]);
1190
- }
1191
- exports.translate = translate;