@luomus/laji-form 15.1.0 → 15.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/dist/laji-form.js +1 -1
  3. package/jsonconfig.json +26 -0
  4. package/migrate.sh +0 -1
  5. package/package.json +8 -8
  6. package/test-export/test-utils.d.ts +100 -54
  7. package/test-export/test-utils.js +102 -84
  8. package/xsel -b +9 -0
  9. package/cypress/fixtures/example.json +0 -5
  10. package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and closes suggestion list (failed).png +0 -0
  11. package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and is marked as suggested (failed).png +0 -0
  12. package/lib/ApiClient.d.ts +0 -46
  13. package/lib/ApiClient.js +0 -93
  14. package/lib/Context.d.ts +0 -8
  15. package/lib/Context.js +0 -18
  16. package/lib/ReactContext.d.ts +0 -7
  17. package/lib/ReactContext.js +0 -5
  18. package/lib/components/BaseComponent.d.ts +0 -9
  19. package/lib/components/BaseComponent.js +0 -29
  20. package/lib/components/LajiForm.d.ts +0 -221
  21. package/lib/components/LajiForm.js +0 -615
  22. package/lib/components/VirtualSchemaField.d.ts +0 -42
  23. package/lib/components/VirtualSchemaField.js +0 -74
  24. package/lib/components/components.d.ts +0 -119
  25. package/lib/components/components.js +0 -606
  26. package/lib/components/fields/AnnotationField.d.ts +0 -34
  27. package/lib/components/fields/AnnotationField.js +0 -242
  28. package/lib/components/fields/AnyToBooleanField.d.ts +0 -18
  29. package/lib/components/fields/AnyToBooleanField.js +0 -20
  30. package/lib/components/fields/ArrayBulkField.d.ts +0 -23
  31. package/lib/components/fields/ArrayBulkField.js +0 -82
  32. package/lib/components/fields/ArrayCombinerField.d.ts +0 -36
  33. package/lib/components/fields/ArrayCombinerField.js +0 -138
  34. package/lib/components/fields/ArrayField.d.ts +0 -39
  35. package/lib/components/fields/ArrayField.js +0 -148
  36. package/lib/components/fields/AudioArrayField.d.ts +0 -22
  37. package/lib/components/fields/AudioArrayField.js +0 -100
  38. package/lib/components/fields/AutoArrayField.d.ts +0 -24
  39. package/lib/components/fields/AutoArrayField.js +0 -56
  40. package/lib/components/fields/AutosuggestField.d.ts +0 -69
  41. package/lib/components/fields/AutosuggestField.js +0 -299
  42. package/lib/components/fields/CombinedValueDisplayField.d.ts +0 -41
  43. package/lib/components/fields/CombinedValueDisplayField.js +0 -100
  44. package/lib/components/fields/ConditionalOnChangeField.d.ts +0 -42
  45. package/lib/components/fields/ConditionalOnChangeField.js +0 -107
  46. package/lib/components/fields/ConditionalUiSchemaField.d.ts +0 -123
  47. package/lib/components/fields/ConditionalUiSchemaField.js +0 -143
  48. package/lib/components/fields/ContextInjectionField.d.ts +0 -24
  49. package/lib/components/fields/ContextInjectionField.js +0 -68
  50. package/lib/components/fields/DataLeakerField.d.ts +0 -40
  51. package/lib/components/fields/DataLeakerField.js +0 -68
  52. package/lib/components/fields/DefaultValueArrayField.d.ts +0 -34
  53. package/lib/components/fields/DefaultValueArrayField.js +0 -59
  54. package/lib/components/fields/DependentBooleanField.d.ts +0 -38
  55. package/lib/components/fields/DependentBooleanField.js +0 -87
  56. package/lib/components/fields/DependentDisableField.d.ts +0 -35
  57. package/lib/components/fields/DependentDisableField.js +0 -71
  58. package/lib/components/fields/EnumRangeArrayField.d.ts +0 -27
  59. package/lib/components/fields/EnumRangeArrayField.js +0 -115
  60. package/lib/components/fields/ExtraLabelRowField.d.ts +0 -38
  61. package/lib/components/fields/ExtraLabelRowField.js +0 -100
  62. package/lib/components/fields/FakePropertyField.d.ts +0 -18
  63. package/lib/components/fields/FakePropertyField.js +0 -48
  64. package/lib/components/fields/FilterArrayField.d.ts +0 -73
  65. package/lib/components/fields/FilterArrayField.js +0 -121
  66. package/lib/components/fields/FlatField.d.ts +0 -29
  67. package/lib/components/fields/FlatField.js +0 -171
  68. package/lib/components/fields/GeocoderField.d.ts +0 -47
  69. package/lib/components/fields/GeocoderField.js +0 -372
  70. package/lib/components/fields/GridLayoutField.d.ts +0 -18
  71. package/lib/components/fields/GridLayoutField.js +0 -32
  72. package/lib/components/fields/HiddenField.d.ts +0 -10
  73. package/lib/components/fields/HiddenField.js +0 -11
  74. package/lib/components/fields/ImageArrayField.d.ts +0 -172
  75. package/lib/components/fields/ImageArrayField.js +0 -697
  76. package/lib/components/fields/ImageDisplayField.d.ts +0 -18
  77. package/lib/components/fields/ImageDisplayField.js +0 -44
  78. package/lib/components/fields/InitiallyHiddenField.d.ts +0 -21
  79. package/lib/components/fields/InitiallyHiddenField.js +0 -58
  80. package/lib/components/fields/InjectDefaultValueField.d.ts +0 -37
  81. package/lib/components/fields/InjectDefaultValueField.js +0 -68
  82. package/lib/components/fields/InjectField.d.ts +0 -46
  83. package/lib/components/fields/InjectField.js +0 -88
  84. package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +0 -25
  85. package/lib/components/fields/InputWithDefaultValueButtonField.js +0 -61
  86. package/lib/components/fields/LocalityField.d.ts +0 -22
  87. package/lib/components/fields/LocalityField.js +0 -94
  88. package/lib/components/fields/LocationChooserField.d.ts +0 -27
  89. package/lib/components/fields/LocationChooserField.js +0 -440
  90. package/lib/components/fields/MapArrayField.d.ts +0 -78
  91. package/lib/components/fields/MapArrayField.js +0 -1783
  92. package/lib/components/fields/MapField.d.ts +0 -48
  93. package/lib/components/fields/MapField.js +0 -434
  94. package/lib/components/fields/MultiAnyToBooleanField.d.ts +0 -25
  95. package/lib/components/fields/MultiAnyToBooleanField.js +0 -100
  96. package/lib/components/fields/MultiArrayField.d.ts +0 -53
  97. package/lib/components/fields/MultiArrayField.js +0 -224
  98. package/lib/components/fields/MultiLanguageField.d.ts +0 -13
  99. package/lib/components/fields/MultiLanguageField.js +0 -52
  100. package/lib/components/fields/MultiTagArrayField.d.ts +0 -36
  101. package/lib/components/fields/MultiTagArrayField.js +0 -142
  102. package/lib/components/fields/NamedPlaceChooserField.d.ts +0 -29
  103. package/lib/components/fields/NamedPlaceChooserField.js +0 -380
  104. package/lib/components/fields/NamedPlaceSaverField.d.ts +0 -29
  105. package/lib/components/fields/NamedPlaceSaverField.js +0 -237
  106. package/lib/components/fields/NestField.d.ts +0 -148
  107. package/lib/components/fields/NestField.js +0 -289
  108. package/lib/components/fields/ObjectField.d.ts +0 -2
  109. package/lib/components/fields/ObjectField.js +0 -119
  110. package/lib/components/fields/PdfArrayField.d.ts +0 -21
  111. package/lib/components/fields/PdfArrayField.js +0 -40
  112. package/lib/components/fields/PrefillingArrayField.d.ts +0 -22
  113. package/lib/components/fields/PrefillingArrayField.js +0 -65
  114. package/lib/components/fields/SchemaField.d.ts +0 -7
  115. package/lib/components/fields/SchemaField.js +0 -109
  116. package/lib/components/fields/ScopeField.d.ts +0 -85
  117. package/lib/components/fields/ScopeField.js +0 -521
  118. package/lib/components/fields/SectionArrayField.d.ts +0 -38
  119. package/lib/components/fields/SectionArrayField.js +0 -618
  120. package/lib/components/fields/SelectTreeField.d.ts +0 -39
  121. package/lib/components/fields/SelectTreeField.js +0 -143
  122. package/lib/components/fields/SingleActiveArrayField.d.ts +0 -49
  123. package/lib/components/fields/SingleActiveArrayField.js +0 -974
  124. package/lib/components/fields/SingleItemArrayField.d.ts +0 -15
  125. package/lib/components/fields/SingleItemArrayField.js +0 -60
  126. package/lib/components/fields/SortArrayField.d.ts +0 -73
  127. package/lib/components/fields/SortArrayField.js +0 -351
  128. package/lib/components/fields/SplitField.d.ts +0 -28
  129. package/lib/components/fields/SplitField.js +0 -65
  130. package/lib/components/fields/StringToArrayField.d.ts +0 -24
  131. package/lib/components/fields/StringToArrayField.js +0 -48
  132. package/lib/components/fields/SumField.d.ts +0 -35
  133. package/lib/components/fields/SumField.js +0 -83
  134. package/lib/components/fields/TableField.d.ts +0 -18
  135. package/lib/components/fields/TableField.js +0 -136
  136. package/lib/components/fields/TagArrayField.d.ts +0 -38
  137. package/lib/components/fields/TagArrayField.js +0 -128
  138. package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +0 -26
  139. package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +0 -81
  140. package/lib/components/fields/UiFieldApplierField.d.ts +0 -30
  141. package/lib/components/fields/UiFieldApplierField.js +0 -106
  142. package/lib/components/fields/UiFieldMapperArrayField.d.ts +0 -42
  143. package/lib/components/fields/UiFieldMapperArrayField.js +0 -121
  144. package/lib/components/fields/UnitCountShorthandField.d.ts +0 -22
  145. package/lib/components/fields/UnitCountShorthandField.js +0 -149
  146. package/lib/components/fields/UnitListShorthandArrayField.d.ts +0 -26
  147. package/lib/components/fields/UnitListShorthandArrayField.js +0 -108
  148. package/lib/components/fields/UnitShorthandField.d.ts +0 -32
  149. package/lib/components/fields/UnitShorthandField.js +0 -220
  150. package/lib/components/templates/ArrayFieldTemplate.d.ts +0 -85
  151. package/lib/components/templates/ArrayFieldTemplate.js +0 -417
  152. package/lib/components/templates/BaseInputTemplate.d.ts +0 -11
  153. package/lib/components/templates/BaseInputTemplate.js +0 -80
  154. package/lib/components/templates/DescriptionField.d.ts +0 -1
  155. package/lib/components/templates/DescriptionField.js +0 -37
  156. package/lib/components/templates/ErrorListTemplate.d.ts +0 -9
  157. package/lib/components/templates/ErrorListTemplate.js +0 -95
  158. package/lib/components/templates/FieldTemplate.d.ts +0 -6
  159. package/lib/components/templates/FieldTemplate.js +0 -112
  160. package/lib/components/templates/ObjectFieldTemplate.d.ts +0 -7
  161. package/lib/components/templates/ObjectFieldTemplate.js +0 -66
  162. package/lib/components/templates/TitleField.d.ts +0 -9
  163. package/lib/components/templates/TitleField.js +0 -51
  164. package/lib/components/widgets/AnyToBooleanWidget.d.ts +0 -20
  165. package/lib/components/widgets/AnyToBooleanWidget.js +0 -49
  166. package/lib/components/widgets/AutosuggestWidget.d.ts +0 -66
  167. package/lib/components/widgets/AutosuggestWidget.js +0 -1127
  168. package/lib/components/widgets/CheckboxWidget.d.ts +0 -37
  169. package/lib/components/widgets/CheckboxWidget.js +0 -139
  170. package/lib/components/widgets/DateTimeWidget.d.ts +0 -62
  171. package/lib/components/widgets/DateTimeWidget.js +0 -251
  172. package/lib/components/widgets/DateWidget.d.ts +0 -23
  173. package/lib/components/widgets/DateWidget.js +0 -41
  174. package/lib/components/widgets/HiddenWidget.d.ts +0 -15
  175. package/lib/components/widgets/HiddenWidget.js +0 -19
  176. package/lib/components/widgets/ImageSelectWidget.d.ts +0 -14
  177. package/lib/components/widgets/ImageSelectWidget.js +0 -57
  178. package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +0 -43
  179. package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +0 -237
  180. package/lib/components/widgets/InputGroupWidget.d.ts +0 -21
  181. package/lib/components/widgets/InputGroupWidget.js +0 -36
  182. package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +0 -21
  183. package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +0 -47
  184. package/lib/components/widgets/NumberWidget.d.ts +0 -13
  185. package/lib/components/widgets/NumberWidget.js +0 -21
  186. package/lib/components/widgets/PlainTextWidget.d.ts +0 -12
  187. package/lib/components/widgets/PlainTextWidget.js +0 -24
  188. package/lib/components/widgets/SelectWidget.d.ts +0 -52
  189. package/lib/components/widgets/SelectWidget.js +0 -158
  190. package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +0 -19
  191. package/lib/components/widgets/SeparatedDateTimeWidget.js +0 -59
  192. package/lib/components/widgets/TaxonImageWidget.d.ts +0 -13
  193. package/lib/components/widgets/TaxonImageWidget.js +0 -30
  194. package/lib/components/widgets/TextSelectWidget.d.ts +0 -25
  195. package/lib/components/widgets/TextSelectWidget.js +0 -94
  196. package/lib/components/widgets/TextareaWidget.d.ts +0 -32
  197. package/lib/components/widgets/TextareaWidget.js +0 -87
  198. package/lib/components/widgets/TimeWidget.d.ts +0 -11
  199. package/lib/components/widgets/TimeWidget.js +0 -19
  200. package/lib/components/widgets/URLWidget.d.ts +0 -14
  201. package/lib/components/widgets/URLWidget.js +0 -12
  202. package/lib/components/widgets/UpperCaseWidget.d.ts +0 -13
  203. package/lib/components/widgets/UpperCaseWidget.js +0 -21
  204. package/lib/index.d.ts +0 -20
  205. package/lib/index.js +0 -50
  206. package/lib/services/blocker-service.d.ts +0 -11
  207. package/lib/services/blocker-service.js +0 -55
  208. package/lib/services/custom-event-service.d.ts +0 -17
  209. package/lib/services/custom-event-service.js +0 -35
  210. package/lib/services/dom-id-service.d.ts +0 -8
  211. package/lib/services/dom-id-service.js +0 -30
  212. package/lib/services/focus-service.d.ts +0 -13
  213. package/lib/services/focus-service.js +0 -60
  214. package/lib/services/id-service.d.ts +0 -22
  215. package/lib/services/id-service.js +0 -130
  216. package/lib/services/key-handler-service.d.ts +0 -56
  217. package/lib/services/key-handler-service.js +0 -184
  218. package/lib/services/root-instance-service.d.ts +0 -25
  219. package/lib/services/root-instance-service.js +0 -49
  220. package/lib/services/settings-service.d.ts +0 -34
  221. package/lib/services/settings-service.js +0 -154
  222. package/lib/services/singleton-map-service.d.ts +0 -23
  223. package/lib/services/singleton-map-service.js +0 -44
  224. package/lib/services/submit-hook-service.d.ts +0 -24
  225. package/lib/services/submit-hook-service.js +0 -73
  226. package/lib/styles.d.ts +0 -1
  227. package/lib/styles.js +0 -4
  228. package/lib/themes/bs3.d.ts +0 -3
  229. package/lib/themes/bs3.js +0 -133
  230. package/lib/themes/bs5.d.ts +0 -3
  231. package/lib/themes/bs5.js +0 -111
  232. package/lib/themes/glyphicon-fa-mapping.d.ts +0 -3
  233. package/lib/themes/glyphicon-fa-mapping.js +0 -271
  234. package/lib/themes/stub.d.ts +0 -3
  235. package/lib/themes/stub.js +0 -82
  236. package/lib/themes/theme.d.ts +0 -233
  237. package/lib/themes/theme.js +0 -2
  238. package/lib/translations.json +0 -847
  239. package/lib/utils.d.ts +0 -171
  240. package/lib/utils.js +0 -1191
  241. package/lib/validation.d.ts +0 -7
  242. package/lib/validation.js +0 -141
  243. package/llol +0 -10
  244. package/llol.pdf +0 -10
  245. package/playwright-report/index.html +0 -62
  246. package/q +0 -196
  247. package/rename.sh +0 -24
  248. package/trip-report.spec.ts +0 -594
@@ -1,184 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Context_1 = require("../Context");
4
- const utils_1 = require("../utils");
5
- /**
6
- *
7
- * A service for adding key listeners. Key events are handled in a custom event handling system, which allows many useful
8
- * features like listening to DOM document root, fine grained control over the order of event bubbling etc and passing any
9
- * needed data to the event handler.
10
- *
11
- * When initialized, it adds a global keydown listener to the document which handles the LajiForm key shortcuts defined in
12
- * uiSchema["ui:shortcuts"].
13
- *
14
- **/
15
- class KeyhandlerService {
16
- constructor(formContext) {
17
- this.shortcuts = {};
18
- this.keyHandleListeners = {};
19
- this.keyHandleIdFunctions = [];
20
- this.blocked = false;
21
- this.globalEventsRootHandler = {};
22
- this.globalEventHandlers = {};
23
- this.addKeyHandler = (id, keyFunctions, additionalParams) => {
24
- if (!this.keyHandleListeners[id])
25
- this.keyHandleListeners[id] = [];
26
- const handleKey = (e) => {
27
- if (this.blocked) {
28
- e.preventDefault();
29
- return;
30
- }
31
- return this.handleKeysWith(id, keyFunctions, e, additionalParams);
32
- };
33
- this.keyHandleIdFunctions.push({ id, keyFunctions, handleKey });
34
- this.keyHandleListeners[id].push(handleKey);
35
- };
36
- this.removeKeyHandler = (_id, _keyFunctions) => {
37
- this.keyHandleIdFunctions.forEach((idFunction, i) => {
38
- const { id, keyFunctions, handleKey } = idFunction;
39
- if (id === _id && _keyFunctions === keyFunctions) {
40
- this.keyHandleIdFunctions.splice(i, 1);
41
- this.keyHandleListeners[id] = this.keyHandleListeners[id].filter((_handleKey) => _handleKey !== handleKey);
42
- }
43
- });
44
- };
45
- this.formContext = formContext;
46
- this.onKeyDown = this.onKeyDown.bind(this);
47
- }
48
- initialize() {
49
- this.addGlobalEventHandler("keydown", this.onKeyDown);
50
- }
51
- destroy() {
52
- this.removeGlobalEventHandler("keydown", this.onKeyDown);
53
- }
54
- block() {
55
- this.blocked = true;
56
- }
57
- unblock() {
58
- this.blocked = false;
59
- }
60
- setShortcuts(shortcuts = {}, keyFunctions) {
61
- this.keyHandleListeners = {};
62
- this.keyHandleIdFunctions = [];
63
- this.keyHandlers = this.getKeyHandlers(shortcuts);
64
- this.addKeyHandler("root", keyFunctions);
65
- this.keyHandlerTargets = this.keyHandlers.reduce((targets, handler) => {
66
- if (typeof handler.target === "string")
67
- targets.push({ id: handler.target, handler });
68
- return targets;
69
- }, []);
70
- this.shortcuts = shortcuts;
71
- }
72
- setFormContext(formContext) {
73
- this.formContext = formContext;
74
- }
75
- getKeyHandlers(shortcuts = {}) {
76
- return Object.keys(shortcuts).reduce((list, keyCombo) => {
77
- const shortcut = shortcuts[keyCombo];
78
- const specials = {
79
- alt: false,
80
- ctrl: false,
81
- shift: false,
82
- };
83
- list.push(keyCombo.split("+").reduce((keyHandler, key) => {
84
- if (key in specials) {
85
- specials[key] = true;
86
- }
87
- keyHandler.conditions.push(e => e.key === key || (key in specials && ((specials[key] && e[`${key}Key`]) || (!specials[key] && !e[`${key}Key`]))));
88
- return keyHandler;
89
- }, Object.assign(Object.assign({}, shortcut), { conditions: [] })));
90
- for (let special in specials) {
91
- if (!specials[special])
92
- list[list.length - 1].conditions.push(e => {
93
- return !e[`${special}Key`];
94
- });
95
- }
96
- return list;
97
- }, []);
98
- }
99
- onKeyDown(e) {
100
- const currentId = this.formContext.utils.findNearestParentSchemaElemId(e.target) || "";
101
- let order = Object.keys(this.keyHandleListeners).filter(id => {
102
- if (currentId.startsWith(id))
103
- return true;
104
- return;
105
- }).sort((a, b) => {
106
- return b.length - a.length;
107
- });
108
- const targets = this.keyHandlerTargets
109
- .filter(({ handler }) => handler.conditions.every(condition => condition(e)))
110
- .map(({ id }) => utils_1.getKeyHandlerTargetId(id, Context_1.default(this.formContext.contextId)));
111
- order = [...targets, ...order];
112
- order.some(id => { var _a; return (_a = this.keyHandleListeners[id]) === null || _a === void 0 ? void 0 : _a.some((keyHandleListener) => keyHandleListener(e)); });
113
- }
114
- /**
115
- * Global event handlers are listened for the whole DOM document. React can't listen to events on document level, hence this is useful.
116
- **/
117
- addGlobalEventHandler(name, fn) {
118
- if (!this.globalEventHandlers[name]) {
119
- this.globalEventsRootHandler[name] = e => {
120
- if (!e.persist)
121
- e.persist = () => { };
122
- const origStopPropagation = e.stopPropagation;
123
- e.stopPropagation = () => {
124
- e._lajiFormStoppedFlag = true;
125
- origStopPropagation.call(e);
126
- };
127
- this.globalEventHandlers[name].some(h => {
128
- if (e._lajiFormStoppedFlag) {
129
- return true;
130
- }
131
- h(e);
132
- return false;
133
- });
134
- };
135
- document.addEventListener(name, this.globalEventsRootHandler[name]);
136
- this.globalEventHandlers[name] = [];
137
- }
138
- this.globalEventHandlers[name].push(fn);
139
- }
140
- removeGlobalEventHandler(name, fn) {
141
- this.globalEventHandlers[name] = this.globalEventHandlers[name].filter(_fn => _fn !== fn);
142
- if (this.globalEventHandlers[name].length === 0) {
143
- delete this.globalEventHandlers[name];
144
- document.removeEventListener(name, this.globalEventsRootHandler[name]);
145
- }
146
- }
147
- handleKeysWith(id, keyFunctions = {}, e, additionalParams = {}) {
148
- if (this.blocked && !utils_1.isDescendant(document.querySelector(".pass-block"), e.target)) {
149
- e.preventDefault();
150
- return;
151
- }
152
- if (utils_1.isDescendant(document.querySelector(".laji-map"), e.target))
153
- return;
154
- function handleKey(keyHandler) {
155
- const returnValue = keyFunctions[keyHandler.fn](e, Object.assign(Object.assign({}, keyHandler), additionalParams));
156
- const eventHandled = returnValue !== undefined ? returnValue : true;
157
- if (eventHandled) {
158
- e.preventDefault();
159
- e.stopPropagation();
160
- }
161
- return eventHandled;
162
- }
163
- const highPriorityHandled = this.keyHandlers.some(keyHandler => {
164
- let target = utils_1.getKeyHandlerTargetId(keyHandler.target, Context_1.default(this.formContext.contextId));
165
- if (keyFunctions[keyHandler.fn] && "target" in keyHandler && id.match(target) && keyHandler.conditions.every(condition => condition(e))) {
166
- if (!handleKey(keyHandler)) {
167
- e.preventDefault();
168
- e.stopPropagation();
169
- }
170
- return true;
171
- }
172
- return false;
173
- });
174
- if (highPriorityHandled)
175
- return highPriorityHandled;
176
- return this.keyHandlers.some(keyHandler => {
177
- if (keyFunctions[keyHandler.fn] && keyHandler.conditions.every(condition => condition(e))) {
178
- return handleKey(keyHandler);
179
- }
180
- return false;
181
- });
182
- }
183
- }
184
- exports.default = KeyhandlerService;
@@ -1,25 +0,0 @@
1
- import ErrorListTemplate from "../components/templates/ErrorListTemplate";
2
- /**
3
- * Used to access the root LajiForm instance from a child component.
4
- */
5
- export default class RootInstanceService {
6
- private schema;
7
- private formData;
8
- private onChangeCallback;
9
- private validateCallback;
10
- private submitWithWarningsCallback;
11
- private mounted;
12
- private errorListInstance;
13
- constructor(schema: any, formData: any, onChange: (formData: any) => void, validate: () => void, submitWithWarnings: () => void);
14
- setFormData(formData: any): void;
15
- getFormData(): any;
16
- onChange(formData: any): void;
17
- setSchema(schema: any): void;
18
- getSchema(): any;
19
- validate(): void;
20
- submitWithWarnings(): void;
21
- setIsMounted(mounted: boolean): void;
22
- isMounted(): boolean;
23
- setErrorListInstance(instance: ErrorListTemplate): void;
24
- getErrorListInstance(): ErrorListTemplate;
25
- }
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Used to access the root LajiForm instance from a child component.
5
- */
6
- class RootInstanceService {
7
- constructor(schema, formData, onChange, validate, submitWithWarnings) {
8
- this.mounted = false;
9
- this.schema = schema;
10
- this.formData = formData;
11
- this.onChangeCallback = onChange;
12
- this.validate = validate;
13
- this.submitWithWarningsCallback = submitWithWarnings;
14
- }
15
- setFormData(formData) {
16
- this.formData = formData;
17
- }
18
- getFormData() {
19
- return this.formData;
20
- }
21
- onChange(formData) {
22
- this.onChangeCallback(formData);
23
- }
24
- setSchema(schema) {
25
- this.schema = schema;
26
- }
27
- getSchema() {
28
- return this.schema;
29
- }
30
- validate() {
31
- this.validateCallback();
32
- }
33
- submitWithWarnings() {
34
- this.submitWithWarningsCallback();
35
- }
36
- setIsMounted(mounted) {
37
- this.mounted = mounted;
38
- }
39
- isMounted() {
40
- return this.mounted;
41
- }
42
- setErrorListInstance(instance) {
43
- this.errorListInstance = instance;
44
- }
45
- getErrorListInstance() {
46
- return this.errorListInstance;
47
- }
48
- }
49
- exports.default = RootInstanceService;
@@ -1,34 +0,0 @@
1
- /// <reference types="react" />
2
- import { FieldProps, WidgetProps } from "../components/LajiForm";
3
- export declare type Settings = Record<string, string>;
4
- declare type OnSettingsChange = (settings: Record<string, string>, global: boolean) => void;
5
- /**
6
- * Handles parsing settings from uiSchema. Settings can be either global or form specific (it's up to the client using LajiForm to pass the global or form specific settings).
7
- */
8
- export default class SettingsService {
9
- settings: Settings;
10
- private settingSavers;
11
- private globalSettingSavers;
12
- private _onSettingsChange;
13
- constructor(onSettingsChange: OnSettingsChange, settings?: Settings);
14
- addSettingSaver: (key: string, fn: () => any, global?: boolean) => void;
15
- removeSettingSaver: (key: string, global?: boolean) => void;
16
- setSettings(settings?: Settings): void;
17
- getSettings(global?: boolean): {};
18
- onSettingsChange: (global?: boolean) => void;
19
- /**
20
- * Should be binded at React Class Component constructor. The component will unbind automatically when unmounted.
21
- * Hooks into the component React hooks componentDidMount, componentWillUnmount & componentDidUpdate.
22
- *
23
- * @param that this of the React component
24
- * @param props The constructor props
25
- */
26
- bind<P extends (FieldProps | WidgetProps)>(that: React.Component<P>, props: P): void;
27
- private loadStateSettings;
28
- loadContextSettings<P extends FieldProps | WidgetProps>(props: P, context: any): any;
29
- private loadSettings;
30
- updateSettingSaver<P extends (FieldProps | WidgetProps)>(that: React.Component<P>): void;
31
- private getSettingsKey;
32
- private getIdSchemaId;
33
- }
34
- export {};
@@ -1,154 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../utils");
4
- const equals = require("deep-equal");
5
- /**
6
- * Handles parsing settings from uiSchema. Settings can be either global or form specific (it's up to the client using LajiForm to pass the global or form specific settings).
7
- */
8
- class SettingsService {
9
- constructor(onSettingsChange, settings = {}) {
10
- this.settings = {};
11
- this.settingSavers = {};
12
- this.globalSettingSavers = {};
13
- this.addSettingSaver = (key, fn, global = false) => {
14
- const settingSavers = global ? this.globalSettingSavers : this.settingSavers;
15
- settingSavers[key] = fn;
16
- };
17
- this.removeSettingSaver = (key, global = false) => {
18
- const settingSavers = global ? this.globalSettingSavers : this.settingSavers;
19
- delete settingSavers[key];
20
- };
21
- this.onSettingsChange = (global = false) => {
22
- const settings = this.getSettings(global);
23
- if (!equals(this.settings, settings)) {
24
- this.settings = settings;
25
- this._onSettingsChange(settings, global);
26
- }
27
- };
28
- this._onSettingsChange = onSettingsChange;
29
- this.settings = settings;
30
- }
31
- setSettings(settings = {}) {
32
- this.settings = settings;
33
- }
34
- getSettings(global = false) {
35
- const settingSavers = global ? this.globalSettingSavers : this.settingSavers;
36
- return Object.keys(settingSavers).reduce((settings, key) => {
37
- try {
38
- const value = settingSavers[key]();
39
- if (value === undefined) { // skip, or JSON parse will error.
40
- return settings;
41
- }
42
- return Object.assign(Object.assign({}, settings), { [key]: value });
43
- }
44
- catch (e) {
45
- // Swallow failing settings parsing.
46
- }
47
- return settings;
48
- }, {});
49
- }
50
- /**
51
- * Should be binded at React Class Component constructor. The component will unbind automatically when unmounted.
52
- * Hooks into the component React hooks componentDidMount, componentWillUnmount & componentDidUpdate.
53
- *
54
- * @param that this of the React component
55
- * @param props The constructor props
56
- */
57
- bind(that, props) {
58
- this.loadContextSettings(props, props.formContext.globals);
59
- that.state = this.loadStateSettings(props, that.state);
60
- const componentDidMount = that.componentDidMount;
61
- const componentWillUnmount = that.componentWillUnmount;
62
- const componentDidUpdate = that.componentDidUpdate;
63
- that.componentDidMount = () => {
64
- componentDidMount === null || componentDidMount === void 0 ? void 0 : componentDidMount.call(that);
65
- this.updateSettingSaver(that);
66
- };
67
- that.componentWillUnmount = () => {
68
- var _a;
69
- componentWillUnmount === null || componentWillUnmount === void 0 ? void 0 : componentWillUnmount.call(that);
70
- (((_a = that.props.uiSchema) === null || _a === void 0 ? void 0 : _a["ui:settings"]) || []).forEach((key) => {
71
- this.removeSettingSaver(this.getSettingsKey(that.props, key));
72
- });
73
- };
74
- that.componentDidUpdate = (prevProps, prevState) => {
75
- componentDidUpdate === null || componentDidUpdate === void 0 ? void 0 : componentDidUpdate.call(that, prevProps, prevState);
76
- if (that.props.uiSchema && (that.props.uiSchema["ui:settings"] || []).some((key) => {
77
- if (key.match(/^%/))
78
- key = key.match(/^%([^/]*)/)[1];
79
- return (!equals(...[prevState, that.state].map(state => utils_1.parseJSONPointer(state, key, !!"safely"))));
80
- })) {
81
- this.onSettingsChange();
82
- }
83
- };
84
- }
85
- loadStateSettings(props, state) {
86
- return this.loadSettings(props, state, /^((?!%))/);
87
- }
88
- loadContextSettings(props, context) {
89
- return this.loadSettings(props, context, /^%/);
90
- }
91
- loadSettings(props, target = {}, rule) {
92
- const { uiSchema, formContext } = props;
93
- if (!(uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:settings"])) {
94
- return target;
95
- }
96
- const { settings } = formContext.services.settings;
97
- uiSchema["ui:settings"].forEach((key) => {
98
- var _a, _b;
99
- if (this.getSettingsKey(props, key) in settings) {
100
- if (key.match(rule)) {
101
- const last = (_b = (_a = key.match(/.*\/(.*)/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : "";
102
- const withoutLastMatch = key.match(/^(%[^/]+)?(\/.*)\/.*$/);
103
- const withoutLast = withoutLastMatch ? withoutLastMatch[2] : "/";
104
- const lastContainer = utils_1.parseJSONPointer(target, withoutLast || "/", "createParents");
105
- lastContainer[last] = JSON.parse(JSON.stringify(settings[this.getSettingsKey(props, key)]));
106
- }
107
- }
108
- });
109
- return target;
110
- }
111
- // JSON Parsing will throw exceptions for paths that aren't initialized. This is intentional -
112
- // we don't want to save undefined values for settings that are not set.
113
- updateSettingSaver(that) {
114
- var _a;
115
- function parseSettingSaver(target, key) {
116
- const splits = key.split("/");
117
- const last = splits.pop() || "";
118
- const lastContainer = utils_1.parseJSONPointer(target, splits.join("/"));
119
- if (lastContainer && last in lastContainer) {
120
- return lastContainer[last];
121
- }
122
- else {
123
- throw new Error("Setting saver parsing failed");
124
- }
125
- }
126
- (((_a = that.props.uiSchema) === null || _a === void 0 ? void 0 : _a["ui:settings"]) || []).forEach((key) => {
127
- this.addSettingSaver(this.getSettingsKey(that.props, key), () => {
128
- if (key.match(/^%/)) {
129
- return parseSettingSaver(that.props.formContext.globals, key.replace(/^%[^/]*/, ""));
130
- }
131
- else {
132
- return parseSettingSaver(that.state, key);
133
- }
134
- });
135
- });
136
- }
137
- // Settings are hashed with setting id, field id, field name and the options path. Settings id is optional, all the others are automatically read.
138
- getSettingsKey(props, key) {
139
- const id = this.getIdSchemaId(props);
140
- //const id = this.props.idSchema?.$id || this.props.id;
141
- const { uiSchema } = props;
142
- const settingsId = uiSchema && uiSchema["ui:settingsId"] !== undefined ? uiSchema["ui:settingsId"] : "";
143
- if (key.match(/^%/)) {
144
- return key;
145
- }
146
- else {
147
- return `${settingsId}#${id}$${uiSchema["ui:field"]}${key}`;
148
- }
149
- }
150
- getIdSchemaId(props) {
151
- return props.idSchema ? props.idSchema.$id : props.id;
152
- }
153
- }
154
- exports.default = SettingsService;
@@ -1,23 +0,0 @@
1
- import LajiMapType from "@luomus/laji-map/lib/map";
2
- import { Options } from "@luomus/laji-map";
3
- /**
4
- * Service used for accessing a singlet on instance of LajiMap. Using a singleton instance increases performance, as
5
- * the map needs to be initialized only once. Control of the map of simply grabbed, making the previous owner lose
6
- * control of the map.
7
- */
8
- export default class SingletonMapService {
9
- map: LajiMapType;
10
- private owner;
11
- destroy(): void;
12
- /**
13
- * Grab control of the singleton map.
14
- * @param instance should be the Map component instance, that is set as the controller of the map.
15
- * @param mapOptions Map options to set to the map.
16
- */
17
- grab(instance: any, mapOptions: Options): LajiMapType;
18
- release(instance: any): void;
19
- /**
20
- * Ask whether given instance has control of the map.
21
- */
22
- amOwner(instance: any): boolean;
23
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const laji_map_1 = require("@luomus/laji-map");
4
- /**
5
- * Service used for accessing a singlet on instance of LajiMap. Using a singleton instance increases performance, as
6
- * the map needs to be initialized only once. Control of the map of simply grabbed, making the previous owner lose
7
- * control of the map.
8
- */
9
- class SingletonMapService {
10
- destroy() {
11
- var _a;
12
- (_a = this.map) === null || _a === void 0 ? void 0 : _a.destroy();
13
- }
14
- /**
15
- * Grab control of the singleton map.
16
- * @param instance should be the Map component instance, that is set as the controller of the map.
17
- * @param mapOptions Map options to set to the map.
18
- */
19
- grab(instance, mapOptions) {
20
- this.owner = instance;
21
- if (!this.map) {
22
- this.map = new laji_map_1.default(mapOptions);
23
- // this.map = singletonMapService.map;
24
- // this.mounted && props.singleton && this.hasSingletonHandle && props.zoomToData && this.map.zoomToData(props.zoomToData);
25
- // props.zoomToData && this.map.zoomToData(props.zoomToData);
26
- }
27
- else {
28
- this.owner.setMapOptions(this.map.getOptions(), mapOptions, this.owner.props.id);
29
- }
30
- return this.map;
31
- }
32
- release(instance) {
33
- if (instance === this.owner) {
34
- this.owner = undefined;
35
- }
36
- }
37
- /**
38
- * Ask whether given instance has control of the map.
39
- */
40
- amOwner(instance) {
41
- return this.owner === instance;
42
- }
43
- }
44
- exports.default = SingletonMapService;
@@ -1,24 +0,0 @@
1
- import { FieldProps, WidgetProps } from "../components/LajiForm";
2
- export interface SubmitHook {
3
- hook: () => void;
4
- promise: Promise<any>;
5
- lajiFormId: string;
6
- relativePointer: string | undefined;
7
- running: boolean;
8
- description?: string;
9
- failed?: boolean;
10
- }
11
- export default class SubmitHookService {
12
- private onSubmitHooksChange;
13
- private submitHooks;
14
- constructor(onSubmitHooksChange: (submitHooks: SubmitHook[]) => void);
15
- private send;
16
- private internalAdd;
17
- /**
18
- * Add a submit hook for a Field component.
19
- */
20
- add(props: Pick<FieldProps, "formData" | "idSchema" | "formContext"> | Pick<WidgetProps, "formData" | "id" | "formContext">, hook: SubmitHook["hook"]): () => Promise<any>;
21
- remove(lajiFormId: string, hook: SubmitHook["hook"]): Promise<void>;
22
- removeAll(): void;
23
- checkHooks(): Promise<void[]>;
24
- }
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../utils");
4
- class SubmitHookService {
5
- constructor(onSubmitHooksChange) {
6
- this.submitHooks = [];
7
- this.onSubmitHooksChange = onSubmitHooksChange;
8
- }
9
- send(submitHooks, callback) {
10
- this.submitHooks = submitHooks;
11
- this.onSubmitHooksChange(submitHooks, callback);
12
- }
13
- internalAdd(_lajiFormId, relativePointer, hook, description) {
14
- const lajiFormId = `${_lajiFormId}`;
15
- let promise;
16
- const _hook = () => {
17
- return new Promise((resolve) => {
18
- let isRetry = false;
19
- const hooks = (this.submitHooks || []).map(hookItem => {
20
- if (hookItem.hook === _hook) {
21
- isRetry = true;
22
- return Object.assign(Object.assign({}, hookItem), { running: true, promise });
23
- }
24
- return hookItem;
25
- });
26
- if (isRetry) {
27
- this.send(hooks);
28
- }
29
- resolve(hook());
30
- }).then(() => {
31
- this.remove(lajiFormId, _hook);
32
- }).catch(e => {
33
- var _a;
34
- this.send((_a = this.submitHooks) === null || _a === void 0 ? void 0 : _a.map(hookItem => hookItem.hook === _hook ? Object.assign(Object.assign({}, hookItem), { e, running: false, failed: true }) : hookItem));
35
- });
36
- };
37
- promise = _hook();
38
- this.send([
39
- ...this.submitHooks,
40
- { hook: _hook, promise, lajiFormId, description, relativePointer, running: true }
41
- ]);
42
- return _hook;
43
- }
44
- /**
45
- * Add a submit hook for a Field component.
46
- */
47
- add(props, hook) {
48
- const id = utils_1.getFieldUUID(props);
49
- const idSchemaId = "id" in props ? props.id : props.idSchema.$id;
50
- const relativePointer = props.formContext.services.ids.getRelativePointer(idSchemaId, id);
51
- return this.internalAdd(id, relativePointer, hook);
52
- }
53
- remove(lajiFormId, hook) {
54
- return new Promise(resolve => {
55
- lajiFormId = `${lajiFormId}`;
56
- const newHooks = this.submitHooks.filter(({ hook: _hook, lajiFormId: _lajiFormId }) => (hook ? _hook !== hook : lajiFormId !== _lajiFormId));
57
- newHooks.length !== this.submitHooks.length ? this.send(newHooks, resolve) : resolve();
58
- });
59
- }
60
- removeAll() {
61
- this.send([]);
62
- }
63
- checkHooks() {
64
- this.send(this.submitHooks.map(hookItem => (Object.assign(Object.assign({}, hookItem), { running: true }))));
65
- return Promise.all(this.submitHooks.map(({ promise, hook }) => {
66
- const setNotRunning = () => {
67
- this.send(this.submitHooks.map(hookItem => (Object.assign(Object.assign({}, hookItem), { running: hookItem.hook === hook ? false : hookItem.running }))));
68
- };
69
- return promise.then(setNotRunning).catch(setNotRunning);
70
- }));
71
- }
72
- }
73
- exports.default = SubmitHookService;
package/lib/styles.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/lib/styles.js DELETED
@@ -1,4 +0,0 @@
1
- require("react-widgets/dist/css/react-widgets.css");
2
- require("@luomus/laji-map/dist/styles.css");
3
- require("react-spinner/react-spinner.css");
4
- require("../playground/styles.css");
@@ -1,3 +0,0 @@
1
- import { Theme } from "./theme";
2
- declare const theme: Theme;
3
- export default theme;