@kbss-cvut/s-forms 0.7.1-alpha-acc6fda.0 → 0.7.1-alpha-1f4e8ac.0

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.
package/dist/s-forms.cjs CHANGED
@@ -1,3729 +1,2 @@
1
- require('core-js/modules/es.array.iterator.js');
2
- require('core-js/modules/es.promise.js');
3
- var React = require('react');
4
- var PropTypes = require('prop-types');
5
- var jsonld = require('jsonld');
6
- var JsonLdUtils = require('jsonld-utils');
7
- require('core-js/modules/es.array.sort.js');
8
- var tsort = require('tsort');
9
- var ReactDOM = require('react-dom');
10
- var reactBootstrap = require('react-bootstrap');
11
- require('core-js/modules/esnext.set.add-all.js');
12
- require('core-js/modules/esnext.set.delete-all.js');
13
- require('core-js/modules/esnext.set.difference.js');
14
- require('core-js/modules/esnext.set.every.js');
15
- require('core-js/modules/esnext.set.filter.js');
16
- require('core-js/modules/esnext.set.find.js');
17
- require('core-js/modules/esnext.set.intersection.js');
18
- require('core-js/modules/esnext.set.is-disjoint-from.js');
19
- require('core-js/modules/esnext.set.is-subset-of.js');
20
- require('core-js/modules/esnext.set.is-superset-of.js');
21
- require('core-js/modules/esnext.set.join.js');
22
- require('core-js/modules/esnext.set.map.js');
23
- require('core-js/modules/esnext.set.reduce.js');
24
- require('core-js/modules/esnext.set.some.js');
25
- require('core-js/modules/esnext.set.symmetric-difference.js');
26
- require('core-js/modules/esnext.set.union.js');
27
- var DatePicker = require('react-datepicker');
28
- var dateFns = require('date-fns');
29
- var YASQE = require('yasgui-yasqe');
30
- require('@triply/yasgui/build/yasgui.min.css');
31
- var InputMask = require('inputmask-core');
32
- require('core-js/modules/es.symbol.description.js');
33
- var Select = require('react-select');
34
- var reactWindow = require('react-window');
35
- var jsxRuntime = require('react/jsx-runtime');
36
- require('core-js/modules/es.regexp.exec.js');
37
- require('core-js/modules/es.string.replace.js');
38
- var TimeAgo = require('javascript-time-ago');
39
- var en$1 = require('javascript-time-ago/locale/en');
40
- var cs$1 = require('javascript-time-ago/locale/cs');
41
- var framerMotion = require('framer-motion');
42
- var reactLoaderSpinner = require('react-loader-spinner');
43
- require('core-js/modules/es.string.trim.js');
44
- var reactIntl = require('react-intl');
45
- var classNames = require('classnames');
46
- var Card = require('react-bootstrap/Card');
47
-
48
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
49
-
50
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
51
- var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
52
- var jsonld__default = /*#__PURE__*/_interopDefaultLegacy(jsonld);
53
- var JsonLdUtils__default = /*#__PURE__*/_interopDefaultLegacy(JsonLdUtils);
54
- var tsort__default = /*#__PURE__*/_interopDefaultLegacy(tsort);
55
- var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
56
- var DatePicker__default = /*#__PURE__*/_interopDefaultLegacy(DatePicker);
57
- var YASQE__default = /*#__PURE__*/_interopDefaultLegacy(YASQE);
58
- var InputMask__default = /*#__PURE__*/_interopDefaultLegacy(InputMask);
59
- var Select__default = /*#__PURE__*/_interopDefaultLegacy(Select);
60
- var TimeAgo__default = /*#__PURE__*/_interopDefaultLegacy(TimeAgo);
61
- var en__default = /*#__PURE__*/_interopDefaultLegacy(en$1);
62
- var cs__default = /*#__PURE__*/_interopDefaultLegacy(cs$1);
63
- var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
64
- var Card__default = /*#__PURE__*/_interopDefaultLegacy(Card);
65
-
66
- function _extends() {
67
- _extends = Object.assign ? Object.assign.bind() : function (target) {
68
- for (var i = 1; i < arguments.length; i++) {
69
- var source = arguments[i];
70
- for (var key in source) {
71
- if (Object.prototype.hasOwnProperty.call(source, key)) {
72
- target[key] = source[key];
73
- }
74
- }
75
- }
76
- return target;
77
- };
78
- return _extends.apply(this, arguments);
79
- }
80
- function _objectWithoutPropertiesLoose(source, excluded) {
81
- if (source == null) return {};
82
- var target = {};
83
- var sourceKeys = Object.keys(source);
84
- var key, i;
85
- for (i = 0; i < sourceKeys.length; i++) {
86
- key = sourceKeys[i];
87
- if (excluded.indexOf(key) >= 0) continue;
88
- target[key] = source[key];
89
- }
90
- return target;
91
- }
92
-
93
- class Logger {
94
- static log(msg) {
95
- console.log(msg);
96
- }
97
- static warn(msg) {
98
- if (console.warn) {
99
- console.warn(msg);
100
- } else {
101
- console.log("WARNING: " + msg);
102
- }
103
- }
104
- static error(msg) {
105
- if (console.error) {
106
- console.error(msg);
107
- } else {
108
- console.log("ERROR: " + msg);
109
- }
110
- }
111
- }
112
-
113
- const _excluded$2 = ["children"];
114
- const FormGenContext = /*#__PURE__*/React__default["default"].createContext({});
115
- const FormGenContextProvider = _ref => {
116
- let {
117
- children
118
- } = _ref,
119
- props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
120
- let options = [];
121
- const loadFormOptions = async (id, query) => {
122
- const option = options[id];
123
- if (option && option.length) {
124
- return option;
125
- }
126
- const data = await props.fetchTypeAheadValues(query);
127
- if (data.length) {
128
- return new Promise(resolve => {
129
- jsonld__default["default"].frame(data, {}, null, (err, framed) => {
130
- const option = framed["@graph"];
131
- options.push(Object.assign({}, option, {
132
- [id]: option
133
- }));
134
- return resolve(option);
135
- });
136
- });
137
- }
138
- Logger.warn(`No data received when loading options using id ${id}`);
139
- return [];
140
- };
141
- const getOptions = id => options[id] || [];
142
- const values = React.useMemo(() => ({
143
- loadFormOptions,
144
- getOptions
145
- }), [loadFormOptions, getOptions]);
146
- return /*#__PURE__*/React__default["default"].createElement(FormGenContext.Provider, _extends({
147
- value: values
148
- }, props), children);
149
- };
150
- FormGenContextProvider.propTypes = {
151
- children: PropTypes__default["default"].element.isRequired,
152
- fetchTypeAheadValues: PropTypes__default["default"].func
153
- };
154
-
155
- var _class$2;
156
- class Constants {}
157
- _class$2 = Constants;
158
- // Default bootstrap column count
159
- Constants.COLUMN_COUNT = 12;
160
- Constants.INPUT_LENGTH_THRESHOLD = 50;
161
- Constants.DATETIME_NUMBER_FORMAT = "x";
162
- /**
163
- * Contains mainly definition of constants used to parse the form declaration.
164
- */
165
- Constants.FORM = "http://onto.fel.cvut.cz/ontologies/documentation/form";
166
- Constants.HAS_SUBQUESTION = "http://onto.fel.cvut.cz/ontologies/documentation/has_related_question";
167
- Constants.HAS_ANSWER = "http://onto.fel.cvut.cz/ontologies/documentation/has_answer";
168
- Constants.HAS_OPTION = "http://onto.fel.cvut.cz/ontologies/form/has-possible-value";
169
- Constants.HAS_OPTIONS_QUERY = "http://onto.fel.cvut.cz/ontologies/form/has-possible-values-query";
170
- Constants.HAS_VALUE_TYPE = "http://onto.fel.cvut.cz/ontologies/form/has-value-type";
171
- Constants.IS_DISABLED = "http://onto.fel.cvut.cz/ontologies/aviation/form-376/is-disabled";
172
- Constants.INPUT_MASK = "http://onto.fel.cvut.cz/ontologies/form/has-input-mask";
173
- Constants.LAYOUT_CLASS = "http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class";
174
- Constants.LAYOUT = {
175
- FORM: "form",
176
- QUESTION_SECTION: "section",
177
- WIZARD_STEP: "wizard-step",
178
- DATE: "date",
179
- TIME: "time",
180
- DATETIME: "datetime",
181
- TEXT: "text",
182
- TEXTAREA: "textarea",
183
- CHECKBOX: "checkbox",
184
- QUESTION_TYPEAHEAD: "type-ahead",
185
- MASKED_INPUT: "masked-input",
186
- ANSWERABLE: "answerable",
187
- SPARQL: "sparql",
188
- TURTLE: "ttl",
189
- DISABLED: "disabled",
190
- HIDDEN: "hidden",
191
- COLLAPSED: "collapsed",
192
- EMPHASISED: "emphasised",
193
- EMPHASISE_ON_RELEVANT: "emphasise-on-relevant",
194
- CATEGORY: ["category-1", "category-2", "category-3", "category-4", "category-5"]
195
- };
196
- Constants.HAS_INITIAL_INPUT_LENGTH = "http://onto.fel.cvut.cz/ontologies/form-layout/has-initial-input-length";
197
- Constants.VALUE_TYPE_CODE = "code";
198
- Constants.VALUE_TYPE_TEXT = "text";
199
- Constants.GENERATED_ROW_SIZE = 1;
200
- Constants.HAS_QUESTION_ORIGIN = "http://onto.fel.cvut.cz/ontologies/form/has-question-origin";
201
- Constants.HAS_ANSWER_ORIGIN = "http://onto.fel.cvut.cz/ontologies/form/has-answer-origin";
202
- Constants.HAS_DATA_VALUE = "http://onto.fel.cvut.cz/ontologies/documentation/has_data_value";
203
- Constants.HAS_OBJECT_VALUE = "http://onto.fel.cvut.cz/ontologies/documentation/has_object_value";
204
- Constants.HELP_DESCRIPTION = "http://purl.org/dc/elements/1.1/description";
205
- Constants.SOURCE = "http://purl.org/dc/elements/1.1/source";
206
- Constants.XSD = {
207
- MAX_EXCLUSIVE: "http://www.w3.org/2001/XMLSchema#maxExclusive",
208
- MAX_INCLUSIVE: "http://www.w3.org/2001/XMLSchema#maxInclusive",
209
- MIN_EXCLUSIVE: "http://www.w3.org/2001/XMLSchema#minExclusive",
210
- MIN_INCLUSIVE: "http://www.w3.org/2001/XMLSchema#minInclusive",
211
- INT: "http://www.w3.org/2001/XMLSchema#int",
212
- INTEGER: "http://www.w3.org/2001/XMLSchema#integer",
213
- NEGATIVE_INTEGER: "http://www.w3.org/2001/XMLSchema#negativeInteger",
214
- NON_NEGATIVE_INTEGER: "http://www.w3.org/2001/XMLSchema#nonNegativeInteger",
215
- NON_POSITIVE_INTEGER: "http://www.w3.org/2001/XMLSchema#nonPositiveInteger",
216
- POSITIVE_INTEGER: "http://www.w3.org/2001/XMLSchema#positiveInteger",
217
- BOOLEAN: "http://www.w3.org/2001/XMLSchema#boolean"
218
- };
219
- Constants.STEP = "http://onto.fel.cvut.cz/ontologies/form/step";
220
- Constants.ACCEPTS_ANSWER_VALUE = "http://onto.fel.cvut.cz/ontologies/form/accepts-answer-value";
221
- Constants.ACCEPTS = "http://onto.fel.cvut.cz/ontologies/form/accepts";
222
- Constants.HAS_DATATYPE = "http://onto.fel.cvut.cz/ontologies/form/has-datatype";
223
- Constants.HAS_LAYOUT_CLASS = "http://onto.fel.cvut.cz/ontologies/form/has-layout-class";
224
- Constants.HAS_POSSIBLE_VALUES_QUERY = "http://onto.fel.cvut.cz/ontologies/form/has-possible-values-query";
225
- Constants.HAS_REQUIRED_VALUE = "http://onto.fel.cvut.cz/ontologies/form/has-required-value";
226
- Constants.HAS_TESTED_QUESTION = "http://onto.fel.cvut.cz/ontologies/form/has-tested-question";
227
- Constants.HAS_TESTED_FORM = "http://onto.fel.cvut.cz/ontologies/form/has-tested-form";
228
- Constants.HAS_UNIT = "http://onto.fel.cvut.cz/ontologies/form/has-unit";
229
- Constants.HAS_VALID_ANSWER = "http://onto.fel.cvut.cz/ontologies/form/has-valid-answer";
230
- Constants.IS_RELEVANT_IF = "http://onto.fel.cvut.cz/ontologies/form/is-relevant-if";
231
- Constants.ACCEPTS_VALIDATION_VALUE = "http://onto.fel.cvut.cz/ontologies/form/accepts-validation-value";
232
- Constants.HAS_VALIDATION_MESSAGE = "http://onto.fel.cvut.cz/ontologies/form/has-validation-message";
233
- Constants.NEGATIVE_CONDITION = "http://onto.fel.cvut.cz/ontologies/form/negative-condition";
234
- Constants.REQUIRES_ANSWER = "http://onto.fel.cvut.cz/ontologies/form/requires-answer";
235
- Constants.REQUIRES_ANSWER_DESCRIPTION_IF = "http://onto.fel.cvut.cz/ontologies/form/requires-answer-description-if";
236
- Constants.REQUIRES_ANSWER_IF = "http://onto.fel.cvut.cz/ontologies/form/requires-answer-if";
237
- Constants.REQUIRES_ANSWER_VALUE = "http://onto.fel.cvut.cz/ontologies/form/requires-answer-value";
238
- Constants.REQUIRES_DESCRIPTION = "http://onto.fel.cvut.cz/ontologies/form/requires-description";
239
- Constants.HAS_PRECEDING_QUESTION = "http://onto.fel.cvut.cz/ontologies/form/has-preceding-question";
240
- Constants.HAS_PRECEDING_VALUE = "http://onto.fel.cvut.cz/ontologies/form/has-preceding-value";
241
- Constants.HAS_MEDIA_CONTENT = "http://onto.fel.cvut.cz/ontologies/form/has-media-content";
242
- Constants.CONDITION = "http://onto.fel.cvut.cz/ontologies/form/condition";
243
- Constants.OR_CONDITION = "http://onto.fel.cvut.cz/ontologies/form/or-condition";
244
- Constants.HAS_SUB_CONDITION = "http://onto.fel.cvut.cz/ontologies/form/has-sub-condition";
245
- Constants.HAS_PATTERN = "http://onto.fel.cvut.cz/ontologies/form-lt/has-pattern";
246
- Constants.HAS_DECLARED_PREFIX = "http://onto.fel.cvut.cz/ontologies/form-spin/has-declared-prefix";
247
- Constants.PREFIX = "http://www.w3.org/ns/shacl#prefix";
248
- Constants.NAMESPACE = "http://www.w3.org/ns/shacl#namespace";
249
- Constants.HAS_COMMENT = "http://onto.fel.cvut.cz/ontologies/form/has-comment";
250
- Constants.HAS_COMMENT_VALUE = "http://onto.fel.cvut.cz/ontologies/form/has-comment-value";
251
- Constants.HAS_AUTHOR = "http://onto.fel.cvut.cz/ontologies/form/has-author";
252
- Constants.HAS_TIMESTAMP = "http://onto.fel.cvut.cz/ontologies/form/has-timestamp";
253
- Constants.NOT_ANSWERED_QUESTION = "http://onto.fel.cvut.cz/ontologies/form/not-answered-question";
254
- Constants.ANSWERED_QUESTION = "http://onto.fel.cvut.cz/ontologies/form/answered-question";
255
- Constants.RDFS_LABEL = JsonLdUtils__default["default"].RDFS_LABEL;
256
- Constants.RDFS_COMMENT = JsonLdUtils__default["default"].RDFS_COMMENT;
257
- Constants.DEFAULT_HAS_CHILD = JsonLdUtils__default["default"].DEFAULT_HAS_CHILD;
258
- Constants.ICONS = {
259
- QUESTION_COMMENTS: "questionComments",
260
- QUESTION_HELP: "questionHelp",
261
- QUESTION_LINK: "questionLink"
262
- };
263
- Constants.ICON_BEHAVIOR = {
264
- ENABLE: "enable",
265
- DISABLE: "disable",
266
- ON_HOVER: "onHover"
267
- };
268
- // Default form options
269
- Constants.DEFAULT_OPTIONS = {
270
- icons: [{
271
- id: _class$2.ICONS.QUESTION_HELP,
272
- behavior: _class$2.ICON_BEHAVIOR.ENABLE
273
- }, {
274
- id: _class$2.ICONS.QUESTION_COMMENTS,
275
- behavior: _class$2.ICON_BEHAVIOR.ON_HOVER
276
- }, {
277
- id: _class$2.ICONS.QUESTION_LINK,
278
- behavior: _class$2.ICON_BEHAVIOR.ON_HOVER
279
- }]
280
- };
281
- Constants.LANG = {
282
- cs: {
283
- locale: "cs",
284
- label: "Čestina"
285
- },
286
- en: {
287
- locale: "en",
288
- label: "English"
289
- }
290
- };
291
-
292
- class Utils {
293
- /**
294
- * Calculates a simple hash of the specified string, much like usual Java implementations.
295
- * @param str The string to compute has for
296
- * @return {number}
297
- */
298
- static getStringHash(str) {
299
- let hash = 0;
300
- const strlen = str ? str.length : 0;
301
- if (strlen === 0) {
302
- return hash;
303
- }
304
- for (let i = 0; i < strlen; i++) {
305
- hash = (hash << 5) - hash + str.charCodeAt(i);
306
- hash = hash & hash; // Convert to 32bit integer
307
- }
308
-
309
- return hash;
310
- }
311
-
312
- /**
313
- * Wraps passed object into new array if it is not array already.
314
- * @param object_or_array An object or array.
315
- * @returns {*} New array containing passed object or passed array.
316
- */
317
- static asArray(object_or_array) {
318
- if (!object_or_array) {
319
- return [];
320
- }
321
- if (object_or_array.constructor === Array) {
322
- return object_or_array;
323
- }
324
- return [object_or_array];
325
- }
326
- static findQuestionById(id, question, reflexive, asserted, transitive) {
327
- if (reflexive) {
328
- if (question["@id"] === id) {
329
- return question;
330
- }
331
- }
332
- const subQuestions = Utils.asArray(question[Constants.HAS_SUBQUESTION]); // we have such method in some kind of json-ld utils
333
- if (asserted) {
334
- for (let q of subQuestions) {
335
- let foundQ = Utils.findQuestionById(id, q, true, false, false);
336
- if (foundQ) return foundQ;
337
- }
338
- }
339
- if (transitive) {
340
- for (let q of subQuestions) {
341
- let foundQ = Utils.findQuestionById(id, q, false, true, true);
342
- if (foundQ) return foundQ;
343
- }
344
- }
345
- return null;
346
- }
347
- }
348
-
349
- class JsonLdObjectMap {
350
- static putObject(id, question) {
351
- JsonLdObjectMap.objectMap[id] = question;
352
- }
353
- static getObject(id) {
354
- return JsonLdObjectMap.objectMap[id];
355
- }
356
- }
357
- JsonLdObjectMap.objectMap = {};
358
-
359
- class JsonLdObjectUtils {
360
- static getFirstObject(subject, predicate) {
361
- const values = jsonld__default["default"].getValues(subject, predicate);
362
- if (values.length === 0) {
363
- //throw "Subject " + subject[@id] + " does not have any value of property " + predicate;
364
- return null;
365
- }
366
- return values[0];
367
- }
368
- static compareValues(jsonLdValue1, jsonLdValue2) {
369
- jsonLdValue1 = typeof jsonLdValue1 === "object" ? jsonLdValue1 : {
370
- "@value": jsonLdValue1
371
- };
372
- jsonLdValue2 = typeof jsonLdValue2 === "object" ? jsonLdValue2 : {
373
- "@value": jsonLdValue2
374
- };
375
-
376
- // TODO remove: workaround for bad persistance of boolean values -- { @value: "true" } instead of { @value: true }
377
- if (jsonLdValue1 && jsonLdValue1["@value"] && jsonLdValue2 && jsonLdValue2["@value"]) {
378
- const strValue1 = typeof jsonLdValue1["@value"] === "string" ? jsonLdValue1["@value"] : JSON.stringify(jsonLdValue1["@value"]);
379
- const strValue2 = typeof jsonLdValue2["@value"] === "string" ? jsonLdValue2["@value"] : JSON.stringify(jsonLdValue2["@value"]);
380
- if (strValue1 === strValue2) {
381
- return true;
382
- }
383
- }
384
- return jsonld__default["default"].compareValues(jsonLdValue1, jsonLdValue2);
385
- }
386
-
387
- /**
388
- * Sorts the specified JSON-LD data using a topological sort over partially ordered set defined by gtProperty.
389
- *
390
- * This is useful for situations where each item only knows its immediate neighbour in the list.
391
- * @param data The data to sort, should be an array
392
- * @param gtProperty Property specifying that an item is greater than another item. It is used for comparison.
393
- *
394
- */
395
- static toplogicalSort(data, gtProperty) {
396
- let swapped;
397
- do {
398
- swapped = false;
399
- for (let i = 0; i < data.length; i++) {
400
- for (let j = i; j < data.length; j++) {
401
- if (data[i][gtProperty]) {
402
- let gtId = typeof data[i][gtProperty] === "object" ? data[i][gtProperty]["@id"] : data[i][gtProperty];
403
- if (gtId === data[j]["@id"]) {
404
- const tmp = data[i];
405
- data[i] = data[j];
406
- data[j] = tmp;
407
- swapped = true;
408
- break;
409
- }
410
- }
411
- }
412
- }
413
- } while (swapped);
414
- return data;
415
- }
416
-
417
- /**
418
- * Sorts the specified JSON-LD data using a topological sort over partially ordered set defined by gtProperty,
419
- * while preserving original order.
420
- *
421
- * This is useful for situations where each item only knows its immediate neighbour in the list.
422
- * @param data The data to sort, should be an array
423
- * @param gtProperty Property specifying that an item is greater than another item. It is used for comparison.
424
- *
425
- */
426
- static orderPreservingToplogicalSort(data, gtProperty) {
427
- const graph = tsort__default["default"]();
428
- const id2ObjectMap = {};
429
- for (let i = 0; i < data.length; i++) {
430
- let currentId = data[i]["@id"];
431
- graph.add(currentId);
432
- id2ObjectMap[currentId] = data[i];
433
- Utils.asArray(data[i][gtProperty]).map(val => typeof val === "object" ? val["@id"] : val).map(val => [val, currentId]).forEach(edge => graph.add(edge));
434
- }
435
- let sortedIds = graph.sort();
436
- for (let i = 0; i < sortedIds.length; i++) {
437
- data[i] = id2ObjectMap[sortedIds[i]];
438
- }
439
- return data;
440
- }
441
- static getCompareLocalizedLabelFunction(intl) {
442
- return (a, b) => {
443
- const aLabel = JsonLdUtils__default["default"].getLocalized(a[JsonLdUtils__default["default"].RDFS_LABEL], intl);
444
- const bLabel = JsonLdUtils__default["default"].getLocalized(b[JsonLdUtils__default["default"].RDFS_LABEL], intl);
445
- if (aLabel < bLabel) {
446
- return -1;
447
- } else if (aLabel > bLabel) {
448
- return 1;
449
- }
450
- return 0;
451
- };
452
- }
453
- static orderByLocalizedLabels(data, intl) {
454
- return data.sort(JsonLdObjectUtils.getCompareLocalizedLabelFunction(intl));
455
- }
456
-
457
- /**
458
- * Evaluates if jsonLdObject has provided id.
459
- * @param jsonLdObject
460
- * @param id
461
- * @returns {boolean}
462
- */
463
- static checkId(jsonLdObject, id) {
464
- if (jsonLdObject === undefined) {
465
- return;
466
- }
467
- if (jsonLdObject.constructor === Array) {
468
- return !!jsonLdObject.find(o => o["@id"] === id);
469
- }
470
- if (jsonLdObject.constructor === Object) {
471
- return jsonLdObject["@id"] === id;
472
- }
473
- }
474
- }
475
-
476
- class FormUtils {
477
- static isForm(structure) {
478
- return JsonLdUtils__default["default"].hasValue(structure, Constants.LAYOUT_CLASS, Constants.LAYOUT.FORM);
479
- }
480
- static isWizardStep(structure) {
481
- return JsonLdUtils__default["default"].hasValue(structure, Constants.LAYOUT_CLASS, Constants.LAYOUT.WIZARD_STEP);
482
- }
483
- static isSection(question) {
484
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.QUESTION_SECTION);
485
- }
486
- static isAnswerable(question) {
487
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.ANSWERABLE);
488
- }
489
- static isTypeahead(question) {
490
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.QUESTION_TYPEAHEAD);
491
- }
492
- static getPossibleValuesQuery(question) {
493
- return JsonLdUtils__default["default"].getJsonAttValue(question, Constants.HAS_OPTIONS_QUERY);
494
- }
495
- static isDisabled(question) {
496
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.DISABLED);
497
- }
498
- static isHidden(question) {
499
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.HIDDEN);
500
- }
501
- static isTextarea(question, answerValue) {
502
- return answerValue && answerValue.length > Constants.INPUT_LENGTH_THRESHOLD && !FormUtils.isTypeahead(question) || JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.TEXTAREA);
503
- }
504
- static isText(question) {
505
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.TEXT);
506
- }
507
- static isCalendar(question) {
508
- return FormUtils.isDate(question) || FormUtils.isTime(question) || FormUtils.isDateTime(question);
509
- }
510
- static isDate(question) {
511
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.DATE);
512
- }
513
- static isTime(question) {
514
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.TIME);
515
- }
516
- static isDateTime(question) {
517
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.DATETIME);
518
- }
519
- static isCheckbox(question) {
520
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.CHECKBOX);
521
- }
522
- static isMaskedInput(question) {
523
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.MASKED_INPUT);
524
- }
525
- static isSparqlInput(question) {
526
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.SPARQL);
527
- }
528
- static isTurtleInput(question) {
529
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.TURTLE);
530
- }
531
- static isCollapsed(question) {
532
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.COLLAPSED);
533
- }
534
- static isEmphasised(question) {
535
- return JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.EMPHASISED);
536
- }
537
- static getCategory(question) {
538
- return Constants.LAYOUT.CATEGORY.find(c => JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, c));
539
- }
540
- static resolveValue(answer) {
541
- if (!answer) {
542
- return null;
543
- }
544
- if (answer[Constants.HAS_OBJECT_VALUE]) {
545
- return answer[Constants.HAS_OBJECT_VALUE]["@id"];
546
- } else {
547
- return JsonLdUtils__default["default"].getJsonAttValue(answer, Constants.HAS_DATA_VALUE);
548
- }
549
- }
550
- static resolveValueObject(answer) {
551
- if (!answer) {
552
- return null;
553
- }
554
- if (answer[Constants.HAS_OBJECT_VALUE]) {
555
- return Utils.asArray(answer[Constants.HAS_OBJECT_VALUE])[0];
556
- }
557
- if (answer[Constants.HAS_DATA_VALUE]) {
558
- return Utils.asArray(answer[Constants.HAS_DATA_VALUE])[0];
559
- }
560
- return null;
561
- }
562
- static isRelevant(question) {
563
- if (!question[Constants.IS_RELEVANT_IF]) {
564
- return true;
565
- }
566
- for (let cond of Utils.asArray(question[Constants.IS_RELEVANT_IF])) {
567
- if (!FormUtils.testCondition(cond)) {
568
- return false;
569
- }
570
- }
571
- return true;
572
- }
573
- static hasValidationLogic(question) {
574
- if (question[Constants.REQUIRES_ANSWER_VALUE]) {
575
- return true;
576
- }
577
- if (question[Constants.REQUIRES_ANSWER]) {
578
- return true;
579
- }
580
- if (question[Constants.REQUIRES_ANSWER_IF]) {
581
- return true;
582
- }
583
- return false;
584
- }
585
- static isValid(question) {
586
- if (question[Constants.HAS_VALID_ANSWER] === false) {
587
- return false;
588
- }
589
- for (const subQ of Utils.asArray(question[Constants.HAS_SUBQUESTION])) {
590
- if (this.isValid(subQ) === false) {
591
- return false;
592
- }
593
- }
594
- return true;
595
- }
596
- static testOrCondition(condition) {
597
- const hasSubCondition = condition[Constants.HAS_SUB_CONDITION];
598
- if (!hasSubCondition) {
599
- console.warn("Or condition does not have any sub-condition !");
600
- }
601
- for (const subC of this._getMappedObjectsArray(hasSubCondition)) {
602
- if (this.testCondition(subC)) {
603
- return true;
604
- }
605
- }
606
- return false;
607
- }
608
- static testCondition(condition) {
609
- const isOrCondition = condition[Constants.HAS_SUB_CONDITION];
610
- const acceptedValidationsValues = condition[Constants.ACCEPTS_VALIDATION_VALUE];
611
- const acceptedAnswerValues = condition[Constants.ACCEPTS_ANSWER_VALUE];
612
- const accepts = condition[Constants.ACCEPTS];
613
- const testedQuestions = condition[Constants.HAS_TESTED_QUESTION];
614
- let question;
615
- if (isOrCondition) {
616
- return this.testOrCondition(condition);
617
- }
618
- if (acceptedValidationsValues && acceptedAnswerValues) {
619
- console.warn("Support for validation and requirement constraints at same time is not implemented !");
620
- }
621
-
622
- // any answer within all subquestions
623
- if (accepts && testedQuestions) {
624
- const arr = Utils.asArray(accepts);
625
- if (arr.length !== 1) {
626
- console.warn("Support for multiple accepts values is not implemented !");
627
- }
628
- if (arr[0]["@id"] === Constants.ANSWERED_QUESTION) {
629
- if (acceptedAnswerValues || acceptedValidationsValues) {
630
- console.warn("Support for accepted answer/validations values is not implemented !");
631
- }
632
- for (const q of this._getMappedObjectsArray(testedQuestions)) {
633
- if (!this.hasAnswer(q)) {
634
- return false;
635
- }
636
- }
637
- return true;
638
- }
639
- console.warn("No support to accept question of type " + arr[0]["@id"] + " !");
640
- }
641
-
642
- // valid answers
643
- if (acceptedValidationsValues && testedQuestions) {
644
- const arr = Utils.asArray(acceptedValidationsValues);
645
- if (arr.length !== 1 || arr[0] !== true && arr[0] !== "true") {
646
- console.warn('Validation values other than "true" are not implemented !');
647
- }
648
- for (const q of Utils.asArray(testedQuestions)) {
649
- question = JsonLdObjectMap.getObject(q["@id"]);
650
- if (question === undefined) {
651
- console.warn("Questions is not loaded in an object map.");
652
- return true;
653
- }
654
- if (this.isValid(question) === false) {
655
- return false;
656
- }
657
- }
658
- return true;
659
- }
660
-
661
- // concrete values
662
- if (acceptedAnswerValues && testedQuestions) {
663
- question = JsonLdObjectMap.getObject(testedQuestions["@id"]);
664
- for (const expValue of Utils.asArray(acceptedAnswerValues)) {
665
- if (!question) {
666
- console.warn("Question is not defined.");
667
- return true;
668
- }
669
- if (!question.hasOwnProperty(Constants.HAS_ANSWER)) {
670
- //console.warn('Question does not have answer value defined.');
671
- return false;
672
- }
673
- const answers = jsonld__default["default"].getValues(question, Constants.HAS_ANSWER);
674
- if (answers.length === 0) {
675
- return false;
676
- }
677
- const qValue = FormUtils.resolveValueObject(answers[0]);
678
- if (qValue && expValue && qValue.hasOwnProperty("@value") && expValue.hasOwnProperty("@id") && qValue["@value"] == expValue["@id"]) {
679
- // TODO remove !, this is temporary fix as type-ahead component returns data-value instead of
680
- // code-value
681
- return true;
682
- }
683
- if (JsonLdObjectUtils.compareValues(qValue, expValue)) {
684
- return true;
685
- }
686
- }
687
- }
688
- return false;
689
- }
690
-
691
- //returns array of valid object while ignoring
692
- static _getMappedObjectsArray(jsonObjects, objectType) {
693
- return Utils.asArray(jsonObjects).map(o => {
694
- const obj = JsonLdObjectMap.getObject(o["@id"]);
695
- if (obj === undefined) {
696
- console.warn((objectType ? objectType : "Object") + ' "' + o["@id"] + '"' + " is not loaded in an object map.");
697
- return null;
698
- }
699
- return obj;
700
- }).filter(function (o) {
701
- return o !== null;
702
- });
703
- }
704
- static hasAnswer(question) {
705
- if (!question) {
706
- return false;
707
- }
708
- if (question.hasOwnProperty(Constants.HAS_ANSWER)) {
709
- const answers = jsonld__default["default"].getValues(question, Constants.HAS_ANSWER);
710
- if (answers.length) {
711
- const qValue = FormUtils.resolveValueObject(answers[0]);
712
- if (qValue) {
713
- if (qValue["@value"] || qValue["@id"]) {
714
- return true;
715
- }
716
- }
717
- }
718
- }
719
- for (const subQ of Utils.asArray(question[Constants.HAS_SUBQUESTION])) {
720
- if (FormUtils.hasAnswer(subQ)) {
721
- return true;
722
- }
723
- }
724
- return false;
725
- }
726
-
727
- /**
728
- * Resolves which format of date/time/datetime value should be used in the datetime picker.
729
- * @param question Question with format info
730
- * @param originalValue Value read from answer, not processed by the rendered component
731
- * @param options Object with datetime formats
732
- * @return {*} Format from Configuration
733
- */
734
- static resolveDateTimeFormat(question, originalValue, options) {
735
- if (typeof originalValue === "number") {
736
- return Constants.DATETIME_NUMBER_FORMAT;
737
- }
738
- if (FormUtils.isDate(question)) {
739
- return options.dateFormat;
740
- } else if (FormUtils.isTime(question)) {
741
- return options.timeFormat;
742
- }
743
- return options.dateTimeFormat;
744
- }
745
- }
746
-
747
- const INITIAL_DATA = {};
748
- const INITIAL_FORM_QUESTIONS_DATA = [];
749
- const FormQuestionsContext = /*#__PURE__*/React__default["default"].createContext({});
750
- const FormQuestionsProvider = props => {
751
- const [data, setData] = React.useState(props.data || INITIAL_DATA);
752
- const [formQuestionsData, setFormQuestionsData] = React.useState(props.formQuestions || INITIAL_FORM_QUESTIONS_DATA);
753
- React.useEffect(() => {
754
- if (props.isFormValid) {
755
- const isValid = FormUtils.isValid(data);
756
- props.isFormValid(isValid);
757
- }
758
- }, []);
759
- React.useEffect(() => {
760
- setData(props.data || INITIAL_DATA);
761
- setFormQuestionsData(props.formQuestions || INITIAL_FORM_QUESTIONS_DATA);
762
- }, [props.data, props.formQuestions]);
763
- const updateData = update => {
764
- if (!update) return;
765
- setData(Object.assign({}, data, update));
766
- };
767
- const updateFormQuestionsData = (index, update) => {
768
- if (!update || index < 0 || index >= formQuestionsData.length) return;
769
- const newFormQuestionsData = [...formQuestionsData];
770
- newFormQuestionsData[index] = Object.assign({}, newFormQuestionsData[index], update);
771
- setFormQuestionsData(newFormQuestionsData);
772
- if (props.isFormValid) {
773
- const isValid = FormUtils.isValid(data);
774
- props.isFormValid(isValid);
775
- }
776
- };
777
- const getData = () => {
778
- return data;
779
- };
780
- const getFormQuestionsData = index => {
781
- return index === null || index === undefined ? formQuestionsData : formQuestionsData[index];
782
- };
783
- const values = React.useMemo(() => ({
784
- updateData,
785
- updateFormQuestionsData,
786
- getData,
787
- getFormQuestionsData
788
- }), [getFormQuestionsData, getData]);
789
- return /*#__PURE__*/React__default["default"].createElement(FormQuestionsContext.Provider, _extends({
790
- value: values
791
- }, props), props.children);
792
- };
793
- FormQuestionsProvider.propTypes = {
794
- children: PropTypes__default["default"].element.isRequired,
795
- data: PropTypes__default["default"].object.isRequired,
796
- formQuestions: PropTypes__default["default"].array.isRequired,
797
- isFormValid: PropTypes__default["default"].func
798
- };
799
-
800
- class DefaultInput extends React__default["default"].Component {
801
- constructor(props) {
802
- super(props);
803
- this.state = {
804
- cursorPosition: 0
805
- };
806
- }
807
- focus() {
808
- ReactDOM__default["default"].findDOMNode(this.input).focus();
809
- }
810
- getInputDOMNode() {
811
- return ReactDOM__default["default"].findDOMNode(this.input);
812
- }
813
- componentDidUpdate(prevProps, prevState, snapshot) {
814
- if (this.fieldDidShrink(prevProps) || this.fieldDidExpand(prevProps)) {
815
- this.updateFieldCursorPosition();
816
- }
817
- }
818
- fieldDidExpand(prevProps) {
819
- return this.props.type === "textarea" && prevProps.type !== "textarea";
820
- }
821
- fieldDidShrink(prevProps) {
822
- return this.props.type === "text" && prevProps.type !== "text";
823
- }
824
- updateFieldCursorPosition() {
825
- this.focus();
826
- this.getInputDOMNode().setSelectionRange(this.state.cursorPosition, this.state.cursorPosition);
827
- }
828
- saveCursorPosition(e) {
829
- this.props.onChange(e);
830
- this.setState({
831
- cursorPosition: e.target.selectionStart
832
- });
833
- }
834
- render() {
835
- switch (this.props.type) {
836
- case "radio":
837
- return this._renderRadio();
838
- case "checkbox":
839
- return this._renderCheckbox();
840
- case "select":
841
- return this._renderSelect();
842
- case "textarea":
843
- return this._renderTextArea();
844
- default:
845
- return this._renderInput();
846
- }
847
- }
848
- _renderCheckbox() {
849
- // TODO change control id to hash of label
850
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form.Group, {
851
- size: "small",
852
- controlId: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
853
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form.Check, _extends({
854
- type: "checkbox",
855
- ref: c => this.input = c
856
- }, this.props, {
857
- label: this.props.label
858
- })));
859
- }
860
- _renderRadio() {
861
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormGroup, {
862
- size: "small"
863
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form.Check, _extends({
864
- type: "radio",
865
- ref: c => this.input = c
866
- }, this.props, {
867
- label: this.props.label
868
- })));
869
- }
870
- _renderSelect() {
871
- // TODO validation
872
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormGroup, {
873
- size: "small"
874
- }, this._renderLabel(), /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormControl, _extends({
875
- as: "select",
876
- ref: c => this.input = c
877
- }, this.props), this.props.children), this.props.validation && /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormControl.Feedback, null), this._renderHelp());
878
- }
879
- _renderLabel() {
880
- return this.props.label ? /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form.Label, null, this.props.label) : null;
881
- }
882
- _renderTextArea() {
883
- // TODO validation
884
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormGroup, {
885
- size: "small"
886
- }, this._renderLabel(), /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormControl, _extends({
887
- ref: c => this.input = c,
888
- as: "textarea"
889
- }, this.props, {
890
- onChange: e => this.saveCursorPosition(e)
891
- })), this.props.validation && /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormControl.Feedback, null), this._renderHelp());
892
- }
893
- _renderHelp() {
894
- return this.props.help ? /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormText, null, this.props.help) : null;
895
- }
896
- _renderInput() {
897
- // TODO validation
898
-
899
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormGroup, {
900
- size: "small"
901
- }, this._renderLabel(), /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormControl, _extends({
902
- ref: c => this.input = c,
903
- as: "input"
904
- }, this.props, {
905
- onChange: e => this.saveCursorPosition(e)
906
- })), this.props.validation && /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormControl.Feedback, null), this._renderHelp());
907
- }
908
- }
909
- DefaultInput.propTypes = {
910
- type: PropTypes__default["default"].string,
911
- label: PropTypes__default["default"].object,
912
- value: PropTypes__default["default"].any,
913
- onChange: PropTypes__default["default"].func,
914
- help: PropTypes__default["default"].string,
915
- validation: PropTypes__default["default"].oneOf(["success", "warning", "error"])
916
- };
917
- DefaultInput.defaultProps = {
918
- type: "text"
919
- };
920
-
921
- const _excluded$1 = ["children"];
922
- const ConfigurationContext = /*#__PURE__*/React__default["default"].createContext({});
923
- const defaultProps = {
924
- components: {
925
- inputComponent: DefaultInput
926
- },
927
- componentsOptions: {
928
- dateTimeAnswer: {
929
- dateFormat: "yyyy-MM-dd",
930
- timeFormat: "HH:mm:ss",
931
- dateTimeFormat: "yyyy-MM-dd HH:mm:ss"
932
- },
933
- readOnly: false
934
- },
935
- options: {
936
- intl: {
937
- locale: "en"
938
- },
939
- i18n: {
940
- "wizard.next": "Next",
941
- "wizard.previous": "Previous",
942
- "section.collapse": "Collapse",
943
- "section.expand": "Expand"
944
- },
945
- modalView: false,
946
- modalProps: {},
947
- horizontalWizardNav: true,
948
- wizardStepButtons: true,
949
- enableForwardSkip: false,
950
- startingStep: 0
951
- }
952
- };
953
- const ConfigurationContextProvider = _ref => {
954
- let {
955
- children
956
- } = _ref,
957
- props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
958
- const values = React.useMemo(() => ({
959
- inputComponent: props.components && props.components.inputComponent || defaultProps.components.inputComponent,
960
- componentsOptions: Object.assign({}, defaultProps.componentsOptions, props.componentsOptions),
961
- options: Object.assign({}, defaultProps.options, props.options),
962
- mapComponent: props.mapComponent
963
- }), [props]);
964
- return /*#__PURE__*/React__default["default"].createElement(ConfigurationContext.Provider, {
965
- value: values
966
- }, children);
967
- };
968
- ConfigurationContextProvider.propTypes = {
969
- children: PropTypes__default["default"].element.isRequired,
970
- components: PropTypes__default["default"].object,
971
- mapComponent: PropTypes__default["default"].func,
972
- options: PropTypes__default["default"].object
973
- };
974
-
975
- var formTemplate = {
976
- "@graph": [
977
- {
978
- "@type": "http://onto.fel.cvut.cz/ontologies/documentation/question",
979
- "http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class": "form",
980
- "http://onto.fel.cvut.cz/ontologies/documentation/has_related_question": [
981
- {
982
- "http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class": [
983
- "wizard-step",
984
- "section"
985
- ],
986
- "http://www.w3.org/2000/01/rdf-schema#label": [
987
- {
988
- "@language": "en",
989
- "@value": "Description"
990
- },
991
- {
992
- "@language": "cs",
993
- "@value": "Popis"
994
- }
995
- ],
996
- "http://onto.fel.cvut.cz/ontologies/documentation/has_related_question": [
997
- {
998
- "@type": "http://onto.fel.cvut.cz/ontologies/documentation/question",
999
- "http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class": [
1000
- "textarea"
1001
- ],
1002
- "http://www.w3.org/2000/01/rdf-schema#label": [
1003
- {
1004
- "@language": "en",
1005
- "@value": "Description"
1006
- },
1007
- {
1008
- "@language": "cs",
1009
- "@value": "Popis"
1010
- }
1011
- ],
1012
- "http://onto.fel.cvut.cz/ontologies/documentation/has_answer": {
1013
- "@type": "http://onto.fel.cvut.cz/ontologies/documentation/answer",
1014
- "http://onto.fel.cvut.cz/ontologies/documentation/has_data_value": ""
1015
- }
1016
- }
1017
- ]
1018
- }
1019
- ]
1020
- }
1021
- ]
1022
- };
1023
-
1024
- class DefaultFormGenerator {
1025
- /**
1026
- * Generates default form for the wizard framework.
1027
- *
1028
- * The form consists of a single step, which contains one text area for the description.
1029
- */
1030
- static generateForm() {
1031
- // Deep copy of the form template to prevent modifications
1032
- return JSON.parse(JSON.stringify(formTemplate));
1033
- }
1034
- }
1035
-
1036
- var _class$1;
1037
- const formShape = {
1038
- root: {
1039
- [Constants.HAS_LAYOUT_CLASS]: Constants.FORM
1040
- },
1041
- expandProperties: [Constants.HAS_SUBQUESTION, Constants.IS_RELEVANT_IF, Constants.HAS_ANSWER, Constants.HAS_DECLARED_PREFIX, Constants.HAS_OPTION, Constants.HAS_COMMENT]
1042
- };
1043
- class JsonLdFramingUtils {
1044
- //TODO revise
1045
-
1046
- /**
1047
- * Performs JSON-LD custom framing using shapes. Shape is declaration of the JSON-LD framing
1048
- * in a language that is incompatible with JSON-LD specification.
1049
- *
1050
- * @param input the JSON-LD input to framing by a shape.
1051
- * @param shape the JSON-LD custom frame configuration using shapes.
1052
- * @param callback(err, framed) called once the operation completes.
1053
- */
1054
- static customFrame(input, shape, callback) {
1055
- if (arguments.length < 2) {
1056
- return jsonld__default["default"].nextTick(function () {
1057
- callback(new TypeError("Could not frame, too few arguments."));
1058
- });
1059
- }
1060
- if (shape === null) {
1061
- //TODO remove
1062
- shape = formShape;
1063
- }
1064
- const flattenedCallback = (e, f) => {
1065
- };
1066
- jsonld__default["default"].flatten(input, null, null, flattenedCallback);
1067
- }
1068
- static expandStructure(structure) {
1069
- let root;
1070
- const id2objectMap = {}; // mapping @id -> object
1071
-
1072
- structure["@graph"].forEach(item => {
1073
- id2objectMap[item["@id"]] = item;
1074
- if (FormUtils.isForm(item)) {
1075
- root = item;
1076
- }
1077
- });
1078
- try {
1079
- this._expandGraph(root, formShape, id2objectMap);
1080
- } catch (e) {
1081
- console.error("Error '" + e + "' occured, while trying to apply frame-ing with custom shape.");
1082
- }
1083
- return id2objectMap;
1084
- }
1085
- static _expandGraph(parentNode, shape, id2ObjectMap) {
1086
- let childArray;
1087
- let child;
1088
- let childId;
1089
- shape.expandProperties.forEach(prop => {
1090
- if (parentNode.hasOwnProperty(prop)) {
1091
- parentNode[prop] = Utils.asArray(parentNode[prop]);
1092
- childArray = parentNode[prop];
1093
- for (let i = 0; i < childArray.length; i++) {
1094
- childId = this._getId(childArray[i]);
1095
- child = id2ObjectMap[childId];
1096
- if (child !== undefined) {
1097
- childArray[i] = child;
1098
- //console.log(childId + " expanded.");
1099
- this._expandGraph(child, shape, id2ObjectMap);
1100
- } else {
1101
- console.warn("object with @id " + childId + " was not defined in input data.");
1102
- }
1103
- }
1104
- }
1105
- });
1106
- }
1107
- static _getId(jsonObject) {
1108
- if (typeof jsonObject === "string") {
1109
- return jsonObject;
1110
- }
1111
- return jsonObject["@id"];
1112
- }
1113
- }
1114
- _class$1 = JsonLdFramingUtils;
1115
- JsonLdFramingUtils.compressStructure = rootNode => {
1116
- let object2IdMap = []; // mapping object -> id
1117
- let idIncluded = new Set();
1118
- object2IdMap = _class$1._compressGraph(rootNode, object2IdMap, idIncluded);
1119
- object2IdMap = object2IdMap.sort((a, b) => {
1120
- if (a["@id"] && b["@id"]) {
1121
- return a["@id"].localeCompare(b["@id"]);
1122
- }
1123
- return 0;
1124
- });
1125
- return object2IdMap;
1126
- };
1127
- JsonLdFramingUtils._compressGraph = (parentNode, object2IdMap, idIncluded) => {
1128
- if (!idIncluded.has(parentNode["@id"])) {
1129
- object2IdMap.push(parentNode);
1130
- idIncluded.add(parentNode["@id"]);
1131
- }
1132
- formShape.expandProperties.forEach(prop => {
1133
- if (parentNode.hasOwnProperty(prop)) {
1134
- const childArray = parentNode[prop];
1135
- for (let i = 0; i < childArray.length; i++) {
1136
- const child = childArray[i];
1137
- if (child !== undefined) {
1138
- childArray[i] = child;
1139
- object2IdMap = _class$1._compressGraph(child, object2IdMap, idIncluded);
1140
- parentNode[prop][i] = {
1141
- "@id": child["@id"]
1142
- };
1143
- }
1144
- }
1145
- }
1146
- });
1147
- return object2IdMap;
1148
- };
1149
-
1150
- class FormGenerator {
1151
- /**
1152
- * Generates a default form with one-step wizard.
1153
- *
1154
- * @param intl Preferred language of questions
1155
- *
1156
- * @return Form definition (a one-step wizard with one question) and form data
1157
- */
1158
- static constructDefaultForm(intl) {
1159
- const defaultFormData = DefaultFormGenerator.generateForm();
1160
- return FormGenerator._constructFormQuestions(defaultFormData, intl);
1161
- }
1162
-
1163
- /**
1164
- * Generates form definition from the specified data-enriched template.
1165
- *
1166
- * @param structure The form structure in JSON-LD
1167
- * @param intl Preferred language of questions
1168
- *
1169
- * @return Promise with generated form definition and form data
1170
- */
1171
- static constructForm(structure, intl) {
1172
- return new Promise(resolve => jsonld__default["default"].flatten(structure, {}, null, (err, structure) => {
1173
- let formProperties;
1174
- let form;
1175
- if (err) {
1176
- Logger.error(err);
1177
- }
1178
- try {
1179
- const [formQuestions, rootForm] = FormGenerator._constructFormQuestions(structure, intl);
1180
- form = rootForm;
1181
- formProperties = {
1182
- formQuestions
1183
- };
1184
- } catch (e) {
1185
- const [formQuestions, rootForm] = FormGenerator.constructDefaultForm(intl);
1186
- form = rootForm;
1187
- formProperties = {
1188
- formQuestions
1189
- };
1190
- }
1191
- return resolve([formProperties, form]);
1192
- }));
1193
- }
1194
- static _constructFormQuestions(structure, intl) {
1195
- let form;
1196
- let formElements;
1197
- let id2ObjectMap;
1198
- let formQuestions = [];
1199
- if (structure["@graph"][0]["@id"] !== undefined) {
1200
- id2ObjectMap = JsonLdFramingUtils.expandStructure(structure); //TODO make as callback
1201
-
1202
- Object.keys(id2ObjectMap).map(key => {
1203
- JsonLdObjectMap.putObject(key, id2ObjectMap[key]);
1204
- });
1205
- } else {
1206
- console.warn("default form is constructed.");
1207
- }
1208
- form = structure["@graph"].find(item => FormUtils.isForm(item));
1209
- formElements = form[Constants.HAS_SUBQUESTION];
1210
- if (!formElements) {
1211
- Logger.error("Could not find any questions in the received data.");
1212
- throw "No questions in the form";
1213
- }
1214
- formQuestions = formElements.filter(item => {
1215
- if (FormUtils.isWizardStep(item) && !FormUtils.isHidden(item)) {
1216
- return true;
1217
- }
1218
- Logger.warn("Item is not a wizard step: " + item);
1219
- return false;
1220
- });
1221
- if (!formQuestions.length) {
1222
- Logger.log("Could not find any wizard steps in the received data. Building form without steps");
1223
- form[Constants.HAS_SUBQUESTION].forEach(question => formQuestions.push(question));
1224
- }
1225
-
1226
- // sort by label
1227
- formQuestions.sort(JsonLdObjectUtils.getCompareLocalizedLabelFunction(intl));
1228
-
1229
- // sort by property
1230
- JsonLdObjectUtils.orderPreservingToplogicalSort(formQuestions, Constants.HAS_PRECEDING_QUESTION);
1231
- return [formQuestions, {
1232
- root: form
1233
- }];
1234
- }
1235
- }
1236
-
1237
- class QuestionAnswerProcessor {
1238
- /**
1239
- * Builds question answer model from the specified wizard data.
1240
- * @param wizardData Global wizard data
1241
- * @param stepData Data from individual wizard steps
1242
- */
1243
- static buildQuestionAnswerModel(wizardData, stepData) {
1244
- const question = {
1245
- subQuestions: []
1246
- };
1247
- let processedQuestion;
1248
- if (wizardData) {
1249
- question.uri = wizardData.root["@id"];
1250
- question.origin = JsonLdUtils__default["default"].getJsonAttValue(wizardData.root, Constants.HAS_QUESTION_ORIGIN, "@id");
1251
- }
1252
- if (stepData) {
1253
- for (let i = 0; i < stepData.length; i++) {
1254
- // This will skip questions corresponding to empty steps in the wizard
1255
- processedQuestion = QuestionAnswerProcessor.processQuestionAnswerHierarchy(stepData[i]);
1256
- if (processedQuestion) {
1257
- question.subQuestions.push(processedQuestion);
1258
- }
1259
- }
1260
- }
1261
- return question;
1262
- }
1263
-
1264
- /**
1265
- * Transforms the QA hierarchy from JSON-LD-based structure to the object model-based one.
1266
- * @param rootQuestion
1267
- */
1268
- static processQuestionAnswerHierarchy(rootQuestion) {
1269
- if (!rootQuestion) {
1270
- return null;
1271
- }
1272
- return QuestionAnswerProcessor._processQuestion(rootQuestion);
1273
- }
1274
- static _processQuestion(question) {
1275
- const result = {};
1276
- result.uri = question["@id"];
1277
- result.origin = JsonLdUtils__default["default"].getJsonAttValue(question, Constants.HAS_QUESTION_ORIGIN, "@id");
1278
- if (question[Constants.HAS_SUBQUESTION]) {
1279
- result.subQuestions = [];
1280
- for (let i = 0; i < question[Constants.HAS_SUBQUESTION].length; i++) {
1281
- result.subQuestions.push(QuestionAnswerProcessor._processQuestion(question[Constants.HAS_SUBQUESTION][i]));
1282
- }
1283
- }
1284
- if (question[Constants.HAS_ANSWER]) {
1285
- result.answers = [];
1286
- if (!Array.isArray(question[Constants.HAS_ANSWER])) {
1287
- question[Constants.HAS_ANSWER] = [question[Constants.HAS_ANSWER]];
1288
- }
1289
- for (let i = 0; i < question[Constants.HAS_ANSWER].length; i++) {
1290
- result.answers.push(QuestionAnswerProcessor.processAnswer(question[Constants.HAS_ANSWER][i]));
1291
- }
1292
- }
1293
- if (question[Constants.HAS_COMMENT]) {
1294
- result.comments = [];
1295
- if (!Array.isArray(question[Constants.HAS_COMMENT])) {
1296
- question[Constants.HAS_COMMENT] = [question[Constants.HAS_COMMENT]];
1297
- }
1298
- for (let i = 0; i < question[Constants.HAS_COMMENT].length; i++) {
1299
- result.comments.push(QuestionAnswerProcessor.processComment(question[Constants.HAS_COMMENT][i]));
1300
- }
1301
- }
1302
- return result;
1303
- }
1304
- static processComment(comment) {
1305
- const result = {};
1306
- result.author = JsonLdUtils__default["default"].getJsonAttValue(comment, Constants.HAS_AUTHOR, "@id");
1307
- result.value = JsonLdUtils__default["default"].getJsonAttValue(comment, Constants.HAS_COMMENT_VALUE);
1308
- result.timestamp = JsonLdUtils__default["default"].getJsonAttValue(comment, Constants.HAS_TIMESTAMP, "@id");
1309
- return result;
1310
- }
1311
- static processAnswer(answer) {
1312
- const result = {};
1313
- result.uri = answer["@id"];
1314
- result.origin = JsonLdUtils__default["default"].getJsonAttValue(answer, Constants.HAS_ANSWER_ORIGIN, "@id");
1315
- if (answer[Constants.HAS_OBJECT_VALUE]) {
1316
- result.codeValue = JsonLdUtils__default["default"].getJsonAttValue(answer, Constants.HAS_OBJECT_VALUE, "@id");
1317
- } else {
1318
- result.textValue = JsonLdUtils__default["default"].getJsonAttValue(answer, Constants.HAS_DATA_VALUE);
1319
- }
1320
- return result;
1321
- }
1322
-
1323
- /**
1324
- * Generates an empty answer for the specified question
1325
- * @param question
1326
- */
1327
- static generateAnswer(question) {
1328
- const answer = {};
1329
- answer[Constants.HAS_DATA_VALUE] = "";
1330
- return answer;
1331
- }
1332
- }
1333
-
1334
- class InputPropertiesResolver$1 {
1335
- static resolveValidationProperties(question) {
1336
- const props = {};
1337
- if (question[Constants.HAS_VALID_ANSWER] === false) {
1338
- props["validation"] = "error";
1339
- props["help"] = question[Constants.HAS_VALIDATION_MESSAGE];
1340
- }
1341
- return props;
1342
- }
1343
- }
1344
- const CheckboxAnswer = props => {
1345
- const {
1346
- inputComponent,
1347
- componentsOptions
1348
- } = React.useContext(ConfigurationContext);
1349
- const question = props.question;
1350
- return /*#__PURE__*/React__default["default"].createElement(inputComponent, Object.assign({}, InputPropertiesResolver$1.resolveValidationProperties(question), {
1351
- type: "checkbox",
1352
- label: props.label,
1353
- title: props.title,
1354
- checked: props.value === true || props.value === "true",
1355
- onChange: e => {
1356
- props.onChange(e.target.checked);
1357
- },
1358
- disabled: componentsOptions.readOnly || FormUtils.isDisabled(question)
1359
- }));
1360
- };
1361
- CheckboxAnswer.propTypes = {
1362
- question: PropTypes__default["default"].object.isRequired,
1363
- label: PropTypes__default["default"].object.isRequired,
1364
- title: PropTypes__default["default"].string,
1365
- value: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].bool]),
1366
- onChange: PropTypes__default["default"].func.isRequired,
1367
- mouseHover: PropTypes__default["default"].bool
1368
- };
1369
-
1370
- const DateTimeAnswer = props => {
1371
- const {
1372
- componentsOptions
1373
- } = React.useContext(ConfigurationContext);
1374
- const dateFormat = FormUtils.resolveDateTimeFormat(props.question, props.value, componentsOptions.dateTimeAnswer);
1375
- const isDate = FormUtils.isDate(props.question);
1376
- const isTime = FormUtils.isTime(props.question);
1377
-
1378
- // workaround because it is not possible to construct Date only with time
1379
- let value;
1380
- if (isTime && props.value) {
1381
- value = new Date(`0 ${props.value}`);
1382
- } else {
1383
- value = props.value ? new Date(props.value) : null;
1384
- }
1385
-
1386
- // DatePicker does not know dateFormat "x", translate to datetime
1387
- const datePickerFormat = dateFormat === "x" ? componentsOptions.dateTimeAnswer.dateTimeFormat : dateFormat;
1388
- const handleDateChange = date => {
1389
- if (dateFormat === Constants.DATETIME_NUMBER_FORMAT) {
1390
- props.onChange(Number(date));
1391
- } else {
1392
- props.onChange(dateFns.format(date, dateFormat));
1393
- }
1394
- };
1395
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormGroup, {
1396
- size: "small"
1397
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form.Label, {
1398
- className: "w-100"
1399
- }, props.label), /*#__PURE__*/React__default["default"].createElement(DatePicker__default["default"], {
1400
- selected: value,
1401
- placeholderText: datePickerFormat.toUpperCase(),
1402
- onChange: handleDateChange,
1403
- showTimeSelect: !isDate,
1404
- showTimeSelectOnly: isTime,
1405
- timeFormat: "HH:mm",
1406
- timeIntervals: 1,
1407
- timeCaption: "Time",
1408
- dateFormat: datePickerFormat,
1409
- className: "form-control",
1410
- disabled: componentsOptions.readOnly || FormUtils.isDisabled(props.question)
1411
- }));
1412
- };
1413
- DateTimeAnswer.propTypes = {
1414
- question: PropTypes__default["default"].object.isRequired,
1415
- label: PropTypes__default["default"].object.isRequired,
1416
- title: PropTypes__default["default"].string,
1417
- value: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]),
1418
- onChange: PropTypes__default["default"].func.isRequired
1419
- };
1420
-
1421
- const NUMERIC_DATATYPES = [Constants.XSD.INT, Constants.XSD.INTEGER, Constants.XSD.NON_NEGATIVE_INTEGER, Constants.XSD.NON_POSITIVE_INTEGER, Constants.XSD.NEGATIVE_INTEGER, Constants.XSD.POSITIVE_INTEGER];
1422
- const NUMBER_RULES = {};
1423
- NUMBER_RULES[Constants.XSD.NON_NEGATIVE_INTEGER] = {
1424
- min: 0
1425
- };
1426
- NUMBER_RULES[Constants.XSD.NON_POSITIVE_INTEGER] = {
1427
- max: 0
1428
- };
1429
- NUMBER_RULES[Constants.XSD.NEGATIVE_INTEGER] = {
1430
- max: -1
1431
- };
1432
- NUMBER_RULES[Constants.XSD.POSITIVE_INTEGER] = {
1433
- min: 1
1434
- };
1435
- const tokenTypes = {
1436
- "string-2": "prefixed",
1437
- atom: "var"
1438
- };
1439
- class InputPropertiesResolver {
1440
- static _resolveInputType(question, value) {
1441
- if (FormUtils.isSparqlInput(question) || FormUtils.isTurtleInput(question) || FormUtils.isTextarea(question, value)) {
1442
- return "textarea";
1443
- } else if (InputPropertiesResolver._isNumeric(question)) {
1444
- return "number";
1445
- }
1446
- return "text";
1447
- }
1448
- static _isNumeric(question) {
1449
- for (let i = 0, len = NUMERIC_DATATYPES.length; i < len; i++) {
1450
- if (JsonLdUtils__default["default"].hasValue(question, Constants.HAS_DATATYPE, NUMERIC_DATATYPES[i])) {
1451
- return true;
1452
- }
1453
- }
1454
- return false;
1455
- }
1456
- static resolveInputProperties(question, value, componentsOptions) {
1457
- let props = {};
1458
- props.type = InputPropertiesResolver._resolveInputType(question, value);
1459
- switch (props["type"]) {
1460
- case "textarea":
1461
- props.rows = 5;
1462
- break;
1463
- case "number":
1464
- props = Object.assign({}, props, InputPropertiesResolver._resolveNumberRestrictions(question), this._resolveStepRestriction(question));
1465
- break;
1466
- }
1467
- props.disabled = componentsOptions.readOnly || FormUtils.isDisabled(question);
1468
- if (question[Constants.HAS_VALID_ANSWER] === false) {
1469
- props.validation = "error";
1470
- props.help = question[Constants.HAS_VALIDATION_MESSAGE];
1471
- }
1472
- return props;
1473
- }
1474
- static _resolveStepRestriction(question) {
1475
- let restriction = {};
1476
- if (question[Constants.STEP] !== undefined) {
1477
- restriction["step"] = JsonLdUtils__default["default"].getJsonAttValue(question, Constants.STEP);
1478
- }
1479
- return restriction;
1480
- }
1481
- static _resolveNumberRestrictions(question) {
1482
- let restriction = {};
1483
- Object.getOwnPropertyNames(NUMBER_RULES).forEach(key => {
1484
- if (JsonLdUtils__default["default"].hasValue(question, Constants.HAS_DATATYPE, key)) {
1485
- restriction = Object.assign({}, restriction, NUMBER_RULES[key]);
1486
- }
1487
- });
1488
- if (question[Constants.XSD.MIN_INCLUSIVE] !== undefined) {
1489
- restriction["min"] = question[Constants.XSD.MIN_INCLUSIVE];
1490
- }
1491
- if (question[Constants.XSD.MIN_EXCLUSIVE] !== undefined) {
1492
- restriction["min"] = question[Constants.XSD.MIN_EXCLUSIVE] + 1;
1493
- }
1494
- if (question[Constants.XSD.MAX_EXCLUSIVE] !== undefined) {
1495
- restriction["max"] = question[Constants.XSD.MAX_EXCLUSIVE] - 1;
1496
- }
1497
- if (question[Constants.XSD.MAX_INCLUSIVE] !== undefined) {
1498
- restriction["max"] = question[Constants.XSD.MAX_INCLUSIVE];
1499
- }
1500
- return restriction;
1501
- }
1502
- }
1503
- const InputAnswer = props => {
1504
- const {
1505
- inputComponent,
1506
- componentsOptions
1507
- } = React.useContext(ConfigurationContext);
1508
- const question = props.question;
1509
- const answer = props.answer;
1510
- let value = props.value;
1511
- // When the value is an object_value, but the layout does not specify neither typeahead nor select,
1512
- // show at least the value's label
1513
- if (answer[Constants.HAS_OBJECT_VALUE] && answer[Constants.HAS_OBJECT_VALUE][JsonLdUtils__default["default"].RDFS_LABEL]) {
1514
- value = JsonLdUtils__default["default"].getJsonAttValue(answer[Constants.HAS_OBJECT_VALUE], JsonLdUtils__default["default"].RDFS_LABEL);
1515
- }
1516
- return /*#__PURE__*/React__default["default"].createElement(inputComponent, Object.assign({}, InputPropertiesResolver.resolveInputProperties(question, value, componentsOptions), {
1517
- label: props.label,
1518
- title: props.title,
1519
- value: value == null ? "" : value,
1520
- onChange: e => {
1521
- props.onChange(e.target.value);
1522
- if (props.sparql || props.turtle) undefined.hide();
1523
- },
1524
- onFocus: e => {
1525
- if (props.sparql) {
1526
- const yasqe = YASQE__default["default"].fromTextArea(e.target);
1527
- yasqe.setValue(value);
1528
- yasqe.on("change", () => {
1529
- props.onChange(yasqe.getValue());
1530
- });
1531
- YASQE__default["default"].Autocompleters.prefixes.appendPrefixIfNeeded = function (yasqe, completerName) {
1532
- if (!yasqe.autocompleters.getTrie(completerName)) return; // no prefixed defined. just stop
1533
- if (!yasqe.options.autocompleters || yasqe.options.autocompleters.indexOf(completerName) === -1) return; //this autocompleter is disabled
1534
- const cur = yasqe.getCursor();
1535
- const token = yasqe.getTokenAt(cur);
1536
- if (tokenTypes[token.type] === "prefixed") {
1537
- const colonIndex = token.string.indexOf(":");
1538
- if (colonIndex !== -1) {
1539
- // check previous token isnt PREFIX, or a '<'(which would mean we are in a uri)
1540
- // const firstTokenString = yasqe.getNextNonWsToken(cur.line).string.toUpperCase();
1541
- const lastNonWsTokenString = yasqe.getPreviousNonWsToken(cur.line, token).string.toUpperCase();
1542
- const previousToken = yasqe.getTokenAt({
1543
- line: cur.line,
1544
- ch: token.start
1545
- }); // needs to be null (beginning of line), or whitespace
1546
- if (lastNonWsTokenString !== "PREFIX" && (previousToken.type === "ws" || previousToken.type == null)) {
1547
- // check whether it isnt defined already (saves us from looping
1548
- // through the array)
1549
- const currentPrefix = token.string.substring(0, colonIndex + 1);
1550
- const queryPrefixes = yasqe.getPrefixesFromQuery();
1551
- if (queryPrefixes[currentPrefix.slice(0, -1)] == null) {
1552
- // ok, so it isnt added yet!
1553
- if (props.question[Constants.HAS_DECLARED_PREFIX] && props.question[Constants.HAS_DECLARED_PREFIX].filter(p => p[Constants.PREFIX] === currentPrefix.slice(0, -1)).length) {
1554
- const prefix = props.question[Constants.HAS_DECLARED_PREFIX].filter(p => p[Constants.PREFIX] === currentPrefix.slice(0, -1));
1555
- const px = {};
1556
- px[prefix[0][Constants.PREFIX]] = prefix[0][Constants.NAMESPACE];
1557
- yasqe.addPrefixes(px);
1558
- } else {
1559
- const completions = yasqe.autocompleters.getTrie(completerName).autoComplete(currentPrefix);
1560
- if (completions.length > 0) {
1561
- yasqe.addPrefixes(completions[0]);
1562
- }
1563
- }
1564
- }
1565
- }
1566
- }
1567
- }
1568
- };
1569
- } else if (props.turtle) {
1570
- console.log("TTL");
1571
- const yate = YASQE__default["default"].fromTextArea(e.target);
1572
- yate.setValue(value);
1573
- yate.on("change", () => {
1574
- props.onChange(yate.getValue());
1575
- });
1576
- }
1577
- }
1578
- }));
1579
- };
1580
- InputAnswer.propTypes = {
1581
- question: PropTypes__default["default"].object.isRequired,
1582
- answer: PropTypes__default["default"].object.isRequired,
1583
- label: PropTypes__default["default"].object.isRequired,
1584
- title: PropTypes__default["default"].string,
1585
- value: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]),
1586
- onChange: PropTypes__default["default"].func.isRequired
1587
- };
1588
-
1589
- const REPLACEMENTS = {
1590
- D: "1",
1591
- M: "1",
1592
- Y: "1",
1593
- h: "1",
1594
- m: "1",
1595
- s: "1"
1596
- };
1597
- class MaskMapper {
1598
- /**
1599
- * Attempts to map regular mask (e.g. date) to the format supported by inputmask-core.
1600
- *
1601
- * E.g. it maps (DD-MM-YYYY) to 11-11-1111.
1602
- *
1603
- * If an unsupported mask character is encountered, it is simply skipped. Datetime masks are processed according to
1604
- * ISO 8601 acronyms (e.g. M for month and m for minute).
1605
- * @param mask The mask to map
1606
- */
1607
- static mapMask(mask) {
1608
- if (!mask) {
1609
- return mask;
1610
- }
1611
- let result = "",
1612
- character;
1613
- for (let i = 0, len = mask.length; i < len; i++) {
1614
- character = mask.charAt(i);
1615
- result += REPLACEMENTS[character] ? REPLACEMENTS[character] : character;
1616
- }
1617
- return result;
1618
- }
1619
- }
1620
-
1621
- const _excluded = ["size", "placeholder"];
1622
- const KEYCODE_Z = 90;
1623
- const KEYCODE_Y = 89;
1624
- function isUndo(e) {
1625
- return e.ctrlKey && e.keyCode === KEYCODE_Z;
1626
- }
1627
- function isRedo(e) {
1628
- return e.ctrlKey && e.keyCode === KEYCODE_Y;
1629
- }
1630
-
1631
- // Copied from https://github.com/insin/react-maskedinput
1632
-
1633
- function getSelection(el) {
1634
- let start;
1635
- let end;
1636
- let rangeEl;
1637
- let clone;
1638
- if (el.selectionStart !== undefined) {
1639
- start = el.selectionStart;
1640
- end = el.selectionEnd;
1641
- } else {
1642
- try {
1643
- el.focus();
1644
- rangeEl = el.createTextRange();
1645
- clone = rangeEl.duplicate();
1646
- rangeEl.moveToBookmark(document.selection.createRange().getBookmark());
1647
- clone.setEndPoint("EndToStart", rangeEl);
1648
- start = clone.text.length;
1649
- end = start + rangeEl.text.length;
1650
- } catch (e) {
1651
- /* not focused or not visible */
1652
- }
1653
- }
1654
- return {
1655
- start,
1656
- end
1657
- };
1658
- }
1659
- function setSelection(el, selection) {
1660
- let rangeEl;
1661
- try {
1662
- if (el.selectionStart !== undefined) {
1663
- el.focus();
1664
- el.setSelectionRange(selection.start, selection.end);
1665
- } else {
1666
- el.focus();
1667
- rangeEl = el.createTextRange();
1668
- rangeEl.collapse(true);
1669
- rangeEl.moveStart("character", selection.start);
1670
- rangeEl.moveEnd("character", selection.end - selection.start);
1671
- rangeEl.select();
1672
- }
1673
- } catch (e) {
1674
- /* not focused or not visible */
1675
- }
1676
- }
1677
- class MaskedInput extends React__default["default"].Component {
1678
- constructor(_props) {
1679
- super(_props);
1680
- this._updatePattern = props => {
1681
- this.mask.setPattern(MaskMapper.mapMask(props.mask), {
1682
- value: this.mask.getRawValue(),
1683
- selection: getSelection(this.input)
1684
- });
1685
- };
1686
- this._updateMaskSelection = () => {
1687
- this.mask.selection = getSelection(this.input);
1688
- };
1689
- this._updateInputSelection = () => {
1690
- setSelection(this.input, this.mask.selection);
1691
- };
1692
- this._onChange = e => {
1693
- const maskValue = this.mask.getValue();
1694
- if (e.target.value !== maskValue) {
1695
- // Cut or delete operations will have shortened the value
1696
- if (e.target.value.length < maskValue.length) {
1697
- const sizeDiff = maskValue.length - e.target.value.length;
1698
- this._updateMaskSelection();
1699
- this.mask.selection.end = this.mask.selection.start + sizeDiff;
1700
- this.mask.backspace();
1701
- }
1702
- const value = this._getDisplayValue();
1703
- e.target.value = value;
1704
- if (value) {
1705
- this._updateInputSelection();
1706
- }
1707
- }
1708
- if (this.props.onChange) {
1709
- this.props.onChange(e);
1710
- }
1711
- };
1712
- this._onKeyDown = e => {
1713
- if (isUndo(e)) {
1714
- e.preventDefault();
1715
- if (this.mask.undo()) {
1716
- e.target.value = this._getDisplayValue();
1717
- this._updateInputSelection();
1718
- if (this.props.onChange) {
1719
- this.props.onChange(e);
1720
- }
1721
- }
1722
- } else if (isRedo(e)) {
1723
- e.preventDefault();
1724
- if (this.mask.redo()) {
1725
- e.target.value = this._getDisplayValue();
1726
- this._updateInputSelection();
1727
- if (this.props.onChange) {
1728
- this.props.onChange(e);
1729
- }
1730
- }
1731
- } else if (e.key === "Backspace") {
1732
- e.preventDefault();
1733
- this._updateMaskSelection();
1734
- if (this.mask.backspace()) {
1735
- const value = this._getDisplayValue();
1736
- e.target.value = value;
1737
- if (value) {
1738
- this._updateInputSelection();
1739
- }
1740
- if (this.props.onChange) {
1741
- this.props.onChange(e);
1742
- }
1743
- }
1744
- }
1745
- };
1746
- this._onKeyPress = e => {
1747
- // Ignore modified key presses
1748
- // Ignore enter key to allow form submission
1749
- if (e.metaKey || e.altKey || e.ctrlKey || e.key === "Enter") {
1750
- return;
1751
- }
1752
- e.preventDefault();
1753
- this._updateMaskSelection();
1754
- if (this.mask.input(e.key)) {
1755
- e.target.value = this.mask.getValue();
1756
- this._updateInputSelection();
1757
- if (this.props.onChange) {
1758
- this.props.onChange(e);
1759
- }
1760
- }
1761
- };
1762
- this._onPaste = e => {
1763
- e.preventDefault();
1764
- this._updateMaskSelection();
1765
- // getData value needed for IE also works in FF & Chrome
1766
- if (this.mask.paste(e.clipboardData.getData("Text"))) {
1767
- e.target.value = this.mask.getValue();
1768
- // Timeout needed for IE
1769
- setTimeout(this._updateInputSelection, 0);
1770
- if (this.props.onChange) {
1771
- this.props.onChange(e);
1772
- }
1773
- }
1774
- };
1775
- this.mask = new InputMask__default["default"]({
1776
- pattern: MaskMapper.mapMask(_props.mask),
1777
- value: _props.value,
1778
- formatCharacters: _props.formatCharacters,
1779
- placeholderChar: _props.placeholderChar || "_"
1780
- });
1781
- }
1782
- componentDidUpdate(prevProps) {
1783
- if (prevProps.mask !== this.props.mask) {
1784
- this._updatePattern(this.props);
1785
- }
1786
- if (prevProps.mask !== this.props.mask && prevProps.value !== this.props.mask) {
1787
- // if we get a new value and a new mask at the same time
1788
- // check if the mask.value is still the initial value
1789
- // - if so use the nextProps value
1790
- // - otherwise the `this.mask` has a value for us (most likely from paste action)
1791
- if (this.mask.getValue() === this.mask.emptyValue) {
1792
- this.mask.setPattern(MaskMapper.mapMask(this.props.mask), {
1793
- value: this.props.value
1794
- });
1795
- } else {
1796
- this.mask.setPattern(MaskMapper.mapMask(this.props.mask), {
1797
- value: this.mask.getRawValue()
1798
- });
1799
- }
1800
- } else if (prevProps.mask !== this.props.mask) {
1801
- this.mask.setPattern(MaskMapper.mapMask(this.props.mask), {
1802
- value: this.mask.getRawValue()
1803
- });
1804
- } else if (prevProps.value !== this.props.value) {
1805
- this.mask.setValue(this.props.value);
1806
- }
1807
- if (prevProps.mask !== this.props.mask && this.mask.selection.start) {
1808
- this._updateInputSelection();
1809
- }
1810
- }
1811
- _getDisplayValue() {
1812
- const value = this.mask.getValue();
1813
- return value === this.mask.emptyValue ? "" : value;
1814
- }
1815
- focus() {
1816
- this.input.focus();
1817
- }
1818
- blur() {
1819
- this.input.blur();
1820
- }
1821
- render() {
1822
- const _this$props = this.props,
1823
- {
1824
- size,
1825
- placeholder
1826
- } = _this$props,
1827
- props = _objectWithoutPropertiesLoose(_this$props, _excluded),
1828
- patternLength = this.mask.pattern.length;
1829
- return /*#__PURE__*/React__default["default"].createElement(this.context.inputComponent, Object.assign({}, props, {
1830
- ref: r => {
1831
- if (r) {
1832
- this.input = r.input ? ReactDOM__default["default"].findDOMNode(r.input) : r;
1833
- }
1834
- },
1835
- maxLength: patternLength,
1836
- onChange: this._onChange,
1837
- onKeyDown: this._onKeyDown,
1838
- onKeyPress: this._onKeyPress,
1839
- onPaste: this._onPaste,
1840
- placeholder: placeholder || this.mask.emptyValue,
1841
- size: size || patternLength,
1842
- value: this._getDisplayValue(),
1843
- type: "text"
1844
- }));
1845
- }
1846
- }
1847
- MaskedInput.contextType = ConfigurationContext;
1848
- MaskedInput.propTypes = {
1849
- mask: PropTypes__default["default"].string.isRequired
1850
- };
1851
- MaskedInput.defaultProps = {
1852
- value: ""
1853
- };
1854
-
1855
- const MaskedInputAnswer = props => {
1856
- const {
1857
- componentsOptions
1858
- } = React.useContext(ConfigurationContext);
1859
- const question = props.question;
1860
- const value = props.value;
1861
- const mask = JsonLdUtils__default["default"].getJsonAttValue(question, Constants.INPUT_MASK);
1862
- if (!mask) {
1863
- Logger.warn("Input mask not provided. Falling back to regular input.");
1864
- return /*#__PURE__*/React__default["default"].createElement(InputAnswer, props);
1865
- }
1866
- return /*#__PURE__*/React__default["default"].createElement(MaskedInput, {
1867
- mask: mask,
1868
- value: value,
1869
- label: props.label,
1870
- title: props.title,
1871
- placeholder: mask,
1872
- onChange: e => props.onChange(e.target.value),
1873
- disabled: componentsOptions.readOnly || FormUtils.isDisabled(question)
1874
- });
1875
- };
1876
- MaskedInputAnswer.propTypes = {
1877
- question: PropTypes__default["default"].object.isRequired,
1878
- answer: PropTypes__default["default"].object.isRequired,
1879
- label: PropTypes__default["default"].object.isRequired,
1880
- title: PropTypes__default["default"].string,
1881
- value: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]),
1882
- onChange: PropTypes__default["default"].func.isRequired
1883
- };
1884
-
1885
- class SelectAnswer extends React__default["default"].Component {
1886
- _generateSelectOptions(options) {
1887
- const rendered = [];
1888
- options.sort(function (a, b) {
1889
- const aLabel = JsonLdUtils__default["default"].getJsonAttValue(a, Constants.RDFS_LABEL),
1890
- bLabel = JsonLdUtils__default["default"].getJsonAttValue(b, Constants.RDFS_LABEL);
1891
- if (aLabel < bLabel) {
1892
- return -1;
1893
- }
1894
- if (aLabel > bLabel) {
1895
- return 1;
1896
- }
1897
- return 0;
1898
- });
1899
- for (let i = 0; i < options.length; i++) {
1900
- rendered.push( /*#__PURE__*/React__default["default"].createElement("option", {
1901
- value: JsonLdUtils__default["default"].getJsonAttValue(options[i], Constants.RDFS_LABEL),
1902
- key: "opt-" + i
1903
- }, JsonLdUtils__default["default"].getJsonAttValue(options[i], Constants.RDFS_LABEL)));
1904
- }
1905
- return rendered;
1906
- }
1907
- render() {
1908
- const question = this.props.question;
1909
- return /*#__PURE__*/React__default["default"].createElement(this.context.inputComponent, {
1910
- type: "select",
1911
- label: this.props.label,
1912
- value: this.props.value,
1913
- title: this.props.title,
1914
- onChange: e => {
1915
- this.props.onChange(e.target.value);
1916
- },
1917
- disabled: this.context.componentsOptions.readOnly || FormUtils.isDisabled(question)
1918
- }, this._generateSelectOptions(question[Constants.HAS_OPTION]));
1919
- }
1920
- }
1921
- SelectAnswer.contextType = ConfigurationContext;
1922
- SelectAnswer.propTypes = {
1923
- question: PropTypes__default["default"].object.isRequired,
1924
- label: PropTypes__default["default"].object.isRequired,
1925
- title: PropTypes__default["default"].string,
1926
- value: PropTypes__default["default"].string,
1927
- onChange: PropTypes__default["default"].func.isRequired
1928
- };
1929
-
1930
- const HEIGHT = 40;
1931
-
1932
- /**
1933
- * Uses react-window to optimize menu list in react-select in case it has a lot of options.
1934
- */
1935
- const OptimizedMenuList = props => {
1936
- const {
1937
- options,
1938
- children,
1939
- maxHeight,
1940
- getValue
1941
- } = props;
1942
- const selectedValues = getValue();
1943
- const initialOffset = selectedValues && selectedValues[0] ? options.indexOf(selectedValues[0]) * HEIGHT : 0;
1944
- return /*#__PURE__*/React__default["default"].createElement(reactWindow.FixedSizeList, {
1945
- height: maxHeight,
1946
- itemCount: children["length"],
1947
- itemSize: HEIGHT,
1948
- initialScrollOffset: initialOffset,
1949
- width: "" // 100% width
1950
- }, ({
1951
- index,
1952
- style
1953
- }) => /*#__PURE__*/React__default["default"].createElement("div", {
1954
- className: "option-wrapper",
1955
- style: style
1956
- }, children[index]));
1957
- };
1958
-
1959
- const processTypeaheadOptions = (options, intl) => {
1960
- if (!options) {
1961
- return [];
1962
- }
1963
-
1964
- // sort by label
1965
- options.sort(JsonLdObjectUtils.getCompareLocalizedLabelFunction(intl));
1966
-
1967
- // sort by property
1968
- JsonLdObjectUtils.orderPreservingToplogicalSort(options, Constants.HAS_PRECEDING_VALUE);
1969
- return JsonLdUtils__default["default"].processTypeaheadOptions(options, intl);
1970
- };
1971
- const TypeaheadAnswer = props => {
1972
- const queryHash = Utils.getStringHash(FormUtils.getPossibleValuesQuery(props.question));
1973
- const formGenContext = React.useContext(FormGenContext);
1974
- const configurationContext = React.useContext(ConfigurationContext);
1975
- const intl = configurationContext.options.intl;
1976
- const [isLoading, setLoading] = React.useState(true);
1977
- const [options, setOptions] = React.useState(processTypeaheadOptions(props.options, intl));
1978
- React.useEffect(() => {
1979
- let isCancelled = false;
1980
- const question = props.question;
1981
- async function loadFormOptions() {
1982
- try {
1983
- const options = await formGenContext.loadFormOptions(queryHash, FormUtils.getPossibleValuesQuery(question));
1984
- if (!isCancelled) {
1985
- setLoading(false);
1986
- setOptions(processTypeaheadOptions(options, intl));
1987
- }
1988
- } catch (error) {
1989
- Logger.error(`An error has occurred during loadFormOptions for query hash: ${queryHash}`);
1990
- }
1991
- }
1992
- if (!question[Constants.HAS_OPTION] && FormUtils.getPossibleValuesQuery(question)) {
1993
- loadFormOptions();
1994
- } else {
1995
- setLoading(false);
1996
- setOptions(processTypeaheadOptions(question[Constants.HAS_OPTION], intl));
1997
- }
1998
- return () => {
1999
- isCancelled = true;
2000
- };
2001
- }, []);
2002
- React.useEffect(() => {
2003
- setOptions(processTypeaheadOptions(props.question[Constants.HAS_OPTION], intl));
2004
- }, [intl]);
2005
- const handleOptionSelectedChange = option => {
2006
- props.onChange(option ? option.id : null);
2007
- };
2008
- const {
2009
- Option
2010
- } = Select.components;
2011
- const DescriptionOption = props => {
2012
- const innerProps = Object.assign({}, props.innerProps, {
2013
- title: props.data.description
2014
- });
2015
- return /*#__PURE__*/React__default["default"].createElement(Option, _extends({}, props, {
2016
- title: props.data.description,
2017
- innerProps: innerProps
2018
- }));
2019
- };
2020
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.FormGroup, {
2021
- size: "small"
2022
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form.Label, null, props.label), /*#__PURE__*/React__default["default"].createElement(Select__default["default"], {
2023
- options: options,
2024
- isSearchable: true,
2025
- isLoading: isLoading,
2026
- isClearable: true,
2027
- isDisabled: isLoading || configurationContext.componentsOptions.readOnly || FormUtils.isDisabled(props.question),
2028
- value: options.filter(option => option.id === props.value),
2029
- placeholder: "",
2030
- getOptionLabel: option => option.name,
2031
- getOptionValue: option => option.id,
2032
- onChange: handleOptionSelectedChange,
2033
- components: {
2034
- MenuList: OptimizedMenuList,
2035
- Option: DescriptionOption
2036
- }
2037
- }));
2038
- };
2039
- TypeaheadAnswer.propTypes = {
2040
- question: PropTypes__default["default"].object.isRequired,
2041
- answer: PropTypes__default["default"].object.isRequired,
2042
- label: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].object]).isRequired,
2043
- title: PropTypes__default["default"].string,
2044
- value: PropTypes__default["default"].string,
2045
- onChange: PropTypes__default["default"].func.isRequired
2046
- };
2047
-
2048
- const CaretSquareUp = ({
2049
- title
2050
- }) => /*#__PURE__*/React__default["default"].createElement("svg", {
2051
- className: "caret-square-up",
2052
- version: "1.1",
2053
- xmlns: "http://www.w3.org/2000/svg",
2054
- width: "24",
2055
- height: "28",
2056
- viewBox: "0 0 24 28"
2057
- }, /*#__PURE__*/React__default["default"].createElement("title", null, title || ""), /*#__PURE__*/React__default["default"].createElement("path", {
2058
- d: "M17.891 17.453c-0.172 0.344-0.516 0.547-0.891 0.547h-10c-0.375 0-0.719-0.203-0.891-0.547-0.172-0.328-0.141-0.734 0.078-1.031l5-7c0.187-0.266 0.484-0.422 0.812-0.422s0.625 0.156 0.812 0.422l5 7c0.219 0.297 0.25 0.703 0.078 1.031zM20 21.5v-15c0-0.266-0.234-0.5-0.5-0.5h-15c-0.266 0-0.5 0.234-0.5 0.5v15c0 0.266 0.234 0.5 0.5 0.5h15c0.266 0 0.5-0.234 0.5-0.5zM24 6.5v15c0 2.484-2.016 4.5-4.5 4.5h-15c-2.484 0-4.5-2.016-4.5-4.5v-15c0-2.484 2.016-4.5 4.5-4.5h15c2.484 0 4.5 2.016 4.5 4.5z"
2059
- }));
2060
-
2061
- const CaretSquareDown = ({
2062
- title
2063
- }) => /*#__PURE__*/React__default["default"].createElement("svg", {
2064
- className: "caret-square-down",
2065
- version: "1.1",
2066
- xmlns: "http://www.w3.org/2000/svg",
2067
- width: "24",
2068
- height: "28",
2069
- viewBox: "0 0 24 28"
2070
- }, /*#__PURE__*/React__default["default"].createElement("title", null, title || ""), /*#__PURE__*/React__default["default"].createElement("path", {
2071
- d: "M17.891 10.547c0.172 0.328 0.141 0.734-0.078 1.031l-5 7c-0.187 0.266-0.484 0.422-0.812 0.422s-0.625-0.156-0.812-0.422l-5-7c-0.219-0.297-0.25-0.703-0.078-1.031 0.172-0.344 0.516-0.547 0.891-0.547h10c0.375 0 0.719 0.203 0.891 0.547zM20 21.5v-15c0-0.266-0.234-0.5-0.5-0.5h-15c-0.266 0-0.5 0.234-0.5 0.5v15c0 0.266 0.234 0.5 0.5 0.5h15c0.266 0 0.5-0.234 0.5-0.5zM24 6.5v15c0 2.484-2.016 4.5-4.5 4.5h-15c-2.484 0-4.5-2.016-4.5-4.5v-15c0-2.484 2.016-4.5 4.5-4.5h15c2.484 0 4.5 2.016 4.5 4.5z"
2072
- }));
2073
-
2074
- const InfoCircle = () => /*#__PURE__*/React__default["default"].createElement("svg", {
2075
- className: "info-circle",
2076
- version: "1.1",
2077
- xmlns: "http://www.w3.org/2000/svg",
2078
- width: "24",
2079
- height: "28",
2080
- viewBox: "0 0 24 28"
2081
- }, /*#__PURE__*/React__default["default"].createElement("title", null, "info-circle"), /*#__PURE__*/React__default["default"].createElement("path", {
2082
- d: "M16 21.5v-2.5c0-0.281-0.219-0.5-0.5-0.5h-1.5v-8c0-0.281-0.219-0.5-0.5-0.5h-5c-0.281 0-0.5 0.219-0.5 0.5v2.5c0 0.281 0.219 0.5 0.5 0.5h1.5v5h-1.5c-0.281 0-0.5 0.219-0.5 0.5v2.5c0 0.281 0.219 0.5 0.5 0.5h7c0.281 0 0.5-0.219 0.5-0.5zM14 7.5v-2.5c0-0.281-0.219-0.5-0.5-0.5h-3c-0.281 0-0.5 0.219-0.5 0.5v2.5c0 0.281 0.219 0.5 0.5 0.5h3c0.281 0 0.5-0.219 0.5-0.5zM24 14c0 6.625-5.375 12-12 12s-12-5.375-12-12 5.375-12 12-12 12 5.375 12 12z"
2083
- }));
2084
-
2085
- const QuestionCircle = () => /*#__PURE__*/React__default["default"].createElement("svg", {
2086
- className: "question-circle",
2087
- version: "1.1",
2088
- xmlns: "http://www.w3.org/2000/svg",
2089
- width: "24",
2090
- height: "28",
2091
- viewBox: "0 0 24 28"
2092
- }, /*#__PURE__*/React__default["default"].createElement("path", {
2093
- d: "M14 21.5v-3c0-0.281-0.219-0.5-0.5-0.5h-3c-0.281 0-0.5 0.219-0.5 0.5v3c0 0.281 0.219 0.5 0.5 0.5h3c0.281 0 0.5-0.219 0.5-0.5zM18 11c0-2.859-3-5-5.688-5-2.547 0-4.453 1.094-5.797 3.328-0.141 0.219-0.078 0.5 0.125 0.656l2.063 1.563c0.078 0.063 0.187 0.094 0.297 0.094 0.141 0 0.297-0.063 0.391-0.187 0.734-0.938 1.047-1.219 1.344-1.437 0.266-0.187 0.781-0.375 1.344-0.375 1 0 1.922 0.641 1.922 1.328 0 0.812-0.422 1.219-1.375 1.656-1.109 0.5-2.625 1.797-2.625 3.313v0.562c0 0.281 0.219 0.5 0.5 0.5h3c0.281 0 0.5-0.219 0.5-0.5v0c0-0.359 0.453-1.125 1.188-1.547 1.188-0.672 2.812-1.578 2.812-3.953zM24 14c0 6.625-5.375 12-12 12s-12-5.375-12-12 5.375-12 12-12 12 5.375 12 12z"
2094
- }));
2095
-
2096
- const IconOverlay = props => {
2097
- const [overlayPlacement, setOverlayPlacement] = React.useState("right");
2098
- const getOverlayPlacement = el => {
2099
- if (!el) return;
2100
- if (el.getBoundingClientRect().x > window.innerWidth / 2) {
2101
- setOverlayPlacement("left");
2102
- } else setOverlayPlacement("right");
2103
- };
2104
- const tooltip = /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Tooltip, {
2105
- className: "tooltip-content",
2106
- id: props.id
2107
- }, props.tooltipContent);
2108
- return /*#__PURE__*/React__default["default"].createElement("span", {
2109
- ref: el => getOverlayPlacement(el)
2110
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.OverlayTrigger, {
2111
- overlay: tooltip,
2112
- placement: props.overlayPlacement || overlayPlacement
2113
- }, /*#__PURE__*/React__default["default"].createElement("span", null, props.children)));
2114
- };
2115
- IconOverlay.propTypes = {
2116
- tooltipContent: PropTypes__default["default"].oneOfType([PropTypes__default["default"].object.isRequired, PropTypes__default["default"].string.isRequired]),
2117
- id: PropTypes__default["default"].string.isRequired,
2118
- overlayPlacement: PropTypes__default["default"].string,
2119
- absolutePosition: PropTypes__default["default"].bool
2120
- };
2121
- IconOverlay.defaultProps = {
2122
- iconClassContainer: "",
2123
- iconClass: "",
2124
- absolutePosition: true
2125
- };
2126
-
2127
- const HelpIcon = props => {
2128
- const [overlayPlacement, setOverlayPlacement] = React.useState("right");
2129
- const getOverlayPlacement = el => {
2130
- if (!el) return;
2131
- if (el.getBoundingClientRect().x > window.innerWidth / 2) {
2132
- setOverlayPlacement("left");
2133
- } else setOverlayPlacement("right");
2134
- };
2135
- return /*#__PURE__*/React__default["default"].createElement("div", {
2136
- ref: el => getOverlayPlacement(el)
2137
- }, /*#__PURE__*/React__default["default"].createElement(IconOverlay, {
2138
- id: "help-icon-tooltip-",
2139
- overlayPlacement: props.overlayPlacement || overlayPlacement,
2140
- absolutePosition: props.absolutePosition,
2141
- tooltipContent: props.text
2142
- }, /*#__PURE__*/React__default["default"].createElement(QuestionCircle, {
2143
- className: props.iconClass
2144
- })));
2145
- };
2146
- HelpIcon.propTypes = {
2147
- text: PropTypes__default["default"].string.isRequired,
2148
- iconClassContainer: PropTypes__default["default"].string,
2149
- iconClass: PropTypes__default["default"].string,
2150
- overlayPlacement: PropTypes__default["default"].string,
2151
- absolutePosition: PropTypes__default["default"].bool
2152
- };
2153
- HelpIcon.defaultProps = {
2154
- iconClassContainer: "",
2155
- iconClass: "",
2156
- absolutePosition: true
2157
- };
2158
-
2159
- const ExternalLink = () => /*#__PURE__*/React__default["default"].createElement("svg", {
2160
- className: "external-link-icon",
2161
- width: "24",
2162
- height: "16",
2163
- viewBox: "0 0 16 16",
2164
- xmlns: "http://www.w3.org/2000/svg"
2165
- }, /*#__PURE__*/React__default["default"].createElement("path", {
2166
- d: "M5,2 C5.55228,2 6,2.44772 6,3 C6,3.55228 5.55228,4 5,4 L4,4 L4,12 L12,12 L12,11 C12,10.4477 12.4477,10 13,10 C13.5523,10 14,10.4477 14,11 L14,12 C14,13.1046 13.1046,14 12,14 L4,14 C2.89543,14 2,13.1046 2,12 L2,4 C2,2.89543 2.89543,2 4,2 L5,2 Z M15,1 L15,5.99814453 C15,6.55043453 14.5523,6.99814453 14,6.99814453 C13.4477,6.99814453 13,6.55043453 13,5.99814453 L13,4.41419 L8.71571,8.69846 C8.32519,9.08899 7.69202,9.08899 7.3015,8.69846 C6.91097,8.30794 6.91097,7.67477 7.3015,7.28425 L11.5858,3 L9.99619141,3 C9.44391141,3 8.99619141,2.55228 8.99619141,2 C8.99619141,1.44772 9.44391141,1 9.99619141,1 L15,1 Z"
2167
- }));
2168
-
2169
- const LinkIcon = props => {
2170
- return /*#__PURE__*/React__default["default"].createElement(IconOverlay, {
2171
- tooltipContent: props.url["@id"] || props.url,
2172
- id: "url-tooltip",
2173
- overlayPlacement: props.overlayPlacement
2174
- }, /*#__PURE__*/React__default["default"].createElement("a", {
2175
- href: props.url["@id"] || props.url,
2176
- target: "_blank",
2177
- className: props.iconClassContainer
2178
- }, /*#__PURE__*/React__default["default"].createElement(ExternalLink, {
2179
- className: props.iconClass
2180
- })));
2181
- };
2182
- LinkIcon.propTypes = {
2183
- url: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string.isRequired, PropTypes__default["default"].object.isRequired]),
2184
- iconClassContainer: PropTypes__default["default"].string,
2185
- iconClass: PropTypes__default["default"].string,
2186
- overlayPlacement: PropTypes__default["default"].string,
2187
- absolutePosition: PropTypes__default["default"].bool
2188
- };
2189
- LinkIcon.defaultProps = {
2190
- iconClassContainer: "",
2191
- iconClass: "",
2192
- absolutePosition: true
2193
- };
2194
-
2195
- const CommentBubble = () => {
2196
- return /*#__PURE__*/React__default["default"].createElement("svg", {
2197
- className: "question-comment",
2198
- version: "1.1",
2199
- id: "Capa_1",
2200
- xmlns: "http://www.w3.org/2000/svg",
2201
- viewBox: "0 0 60 60",
2202
- width: "24",
2203
- height: "28"
2204
- }, /*#__PURE__*/React__default["default"].createElement("path", {
2205
- d: "M30,1.5c-16.542,0-30,12.112-30,27c0,5.204,1.646,10.245,4.768,14.604c-0.591,6.537-2.175,11.39-4.475,13.689 c-0.304,0.304-0.38,0.769-0.188,1.153C0.275,58.289,0.625,58.5,1,58.5c0.046,0,0.092-0.003,0.139-0.01 c0.405-0.057,9.813-1.411,16.618-5.339C21.621,54.71,25.737,55.5,30,55.5c16.542,0,30-12.112,30-27S46.542,1.5,30,1.5z M16,32.5 c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S18.206,32.5,16,32.5z M30,32.5c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4 S32.206,32.5,30,32.5z M44,32.5c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S46.206,32.5,44,32.5z"
2206
- }));
2207
- };
2208
-
2209
- const RecycleBin = () => /*#__PURE__*/React__default["default"].createElement("svg", {
2210
- className: "recycle-bin-icon",
2211
- version: "1.1",
2212
- xmlns: "http://www.w3.org/2000/svg",
2213
- height: "15px",
2214
- width: "15px",
2215
- viewBox: "0 0 512 512"
2216
- }, /*#__PURE__*/React__default["default"].createElement("g", null, /*#__PURE__*/React__default["default"].createElement("g", null, /*#__PURE__*/React__default["default"].createElement("path", {
2217
- d: "M331.636,69.818V0H180.364v69.818h-128v128h34.909V512h337.455V197.818h34.909v-128H331.636z M215.273,34.909h81.455\nv34.909h-81.455V34.909z M389.818,477.091H122.182V197.818h267.636V477.091z M424.727,162.909H87.273v-58.182h337.455V162.909z"
2218
- }))), /*#__PURE__*/React__default["default"].createElement("g", null, /*#__PURE__*/React__default["default"].createElement("g", null, /*#__PURE__*/React__default["default"].createElement("rect", {
2219
- x: "168.727",
2220
- y: "256",
2221
- width: "34.909",
2222
- height: "162.909"
2223
- }))), /*#__PURE__*/React__default["default"].createElement("g", null, /*#__PURE__*/React__default["default"].createElement("g", null, /*#__PURE__*/React__default["default"].createElement("rect", {
2224
- x: "308.364",
2225
- y: "256",
2226
- width: "34.909",
2227
- height: "162.909"
2228
- }))), /*#__PURE__*/React__default["default"].createElement("g", null, /*#__PURE__*/React__default["default"].createElement("g", null, /*#__PURE__*/React__default["default"].createElement("rect", {
2229
- x: "238.545",
2230
- y: "256",
2231
- width: "34.909",
2232
- height: "162.909"
2233
- }))));
2234
-
2235
- const UNKNOWN_AUTHOR = "Unknown author";
2236
- const CommentView = props => {
2237
- const {
2238
- options
2239
- } = React.useContext(ConfigurationContext);
2240
- const [showIRI, setShowIRI] = React.useState(false);
2241
- const [showRecycleBin, setShowRecycleBin] = React.useState(false);
2242
- TimeAgo__default["default"].addLocale(cs__default["default"]);
2243
- TimeAgo__default["default"].addLocale(en__default["default"]);
2244
- TimeAgo__default["default"].setDefaultLocale(Constants.LANG.en.locale);
2245
- const time = new TimeAgo__default["default"](options.intl.locale);
2246
- const getAuthorLabel = () => {
2247
- if (options && options.users) {
2248
- const users = options.users;
2249
- const currentUser = users.find(c => c.id === options.currentUser);
2250
- if (props.author) {
2251
- if (currentUser.label) {
2252
- return currentUser.label;
2253
- } else {
2254
- return getAuthorIRIAbbreviation();
2255
- }
2256
- }
2257
- }
2258
- return UNKNOWN_AUTHOR;
2259
- };
2260
- const getAuthorIRIAbbreviation = () => {
2261
- const fullAuthor = props.author["@id"];
2262
- return fullAuthor.replace(/.*[#\/]/, "... ");
2263
- };
2264
- const getAuthorIRI = () => {
2265
- if (props.author) {
2266
- return Object.values(props.author).toString();
2267
- }
2268
- return UNKNOWN_AUTHOR;
2269
- };
2270
- const renderAuthor = () => {
2271
- return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, showIRI ? /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, getAuthorLabel(), /*#__PURE__*/React__default["default"].createElement(LinkIcon, {
2272
- iconClassContainer: "emphasise-on-relevant-icon",
2273
- url: getAuthorIRI()
2274
- })) : getAuthorLabel());
2275
- };
2276
- const renderTimeAgo = () => {
2277
- const getTimeAgoFormat = () => {
2278
- return time.format(parseInt(props.timestamp));
2279
- };
2280
- const getUTCFormat = () => {
2281
- let dateOptions = {
2282
- weekday: "long",
2283
- year: "numeric",
2284
- month: "long",
2285
- day: "numeric",
2286
- hour: "numeric",
2287
- minute: "numeric",
2288
- second: "numeric"
2289
- };
2290
- const date = new Date(parseInt(props.timestamp));
2291
- return new Intl.DateTimeFormat(options.intl.locale, dateOptions).format(date);
2292
- };
2293
- return /*#__PURE__*/React__default["default"].createElement(IconOverlay, {
2294
- id: "exact-time-overlay",
2295
- tooltipContent: getUTCFormat()
2296
- }, getTimeAgoFormat());
2297
- };
2298
- const handleCommentAuthorMouseEnter = () => {
2299
- setShowIRI(!showIRI);
2300
- };
2301
- const handleCommentBinMouseEnter = () => {
2302
- setShowRecycleBin(true);
2303
- };
2304
- const handleCommentBinMouseLeave = () => {
2305
- setShowRecycleBin(false);
2306
- };
2307
- const handleDeleteCommentClick = () => {
2308
- props.onDeleteQuestionComment(props.index);
2309
- props.onDeleteViewComment();
2310
- };
2311
- return /*#__PURE__*/React__default["default"].createElement("div", {
2312
- className: "comment-content",
2313
- onMouseEnter: handleCommentBinMouseEnter,
2314
- onMouseLeave: handleCommentBinMouseLeave
2315
- }, /*#__PURE__*/React__default["default"].createElement("div", {
2316
- className: "row"
2317
- }, /*#__PURE__*/React__default["default"].createElement("div", {
2318
- className: "col-auto comment-author",
2319
- onMouseEnter: handleCommentAuthorMouseEnter,
2320
- onMouseLeave: handleCommentAuthorMouseEnter
2321
- }, renderAuthor()), /*#__PURE__*/React__default["default"].createElement("div", {
2322
- className: "col-auto text-muted comment-timestamp"
2323
- }, renderTimeAgo()), showRecycleBin ? /*#__PURE__*/React__default["default"].createElement(framerMotion.motion.div, {
2324
- className: "comment-delete emphasise-on-relevant-icon",
2325
- whileHover: {
2326
- scale: 1.2
2327
- },
2328
- whileTap: {
2329
- scale: 0.9
2330
- },
2331
- onClick: handleDeleteCommentClick
2332
- }, /*#__PURE__*/React__default["default"].createElement(RecycleBin, null)) : null), /*#__PURE__*/React__default["default"].createElement("div", {
2333
- className: "row"
2334
- }, /*#__PURE__*/React__default["default"].createElement("div", {
2335
- className: "col comment-value"
2336
- }, props.commentValue)));
2337
- };
2338
- CommentView.propTypes = {
2339
- author: PropTypes__default["default"].object,
2340
- timestamp: PropTypes__default["default"].string.isRequired,
2341
- commentValue: PropTypes__default["default"].string.isRequired,
2342
- onDeleteQuestionComment: PropTypes__default["default"].func.isRequired,
2343
- onDeleteViewComment: PropTypes__default["default"].func,
2344
- index: PropTypes__default["default"].number.isRequired
2345
- };
2346
-
2347
- const CommentList = ({
2348
- comments,
2349
- onDeleteCommentClick
2350
- }) => {
2351
- const commentEndRef = React.useRef(null);
2352
- const [isDeleting, setIsDeleting] = React.useState(false);
2353
- const handleDeleteViewComment = () => {
2354
- setIsDeleting(true);
2355
- setTimeout(() => {
2356
- setIsDeleting(false);
2357
- }, 2000);
2358
- };
2359
- React.useEffect(() => {
2360
- if (commentEndRef.current === null) {
2361
- return;
2362
- }
2363
- commentEndRef.current.scrollTop = commentEndRef.current.scrollHeight;
2364
- }, [JSON.stringify(comments)]);
2365
- return jsxRuntime.jsx("span", {
2366
- children: isDeleting ? jsxRuntime.jsxs("div", {
2367
- className: "comment-delete",
2368
- children: [jsxRuntime.jsx(reactLoaderSpinner.Rings, {
2369
- color: "#00BFFF",
2370
- height: 80,
2371
- width: 80
2372
- }), jsxRuntime.jsx("p", {
2373
- children: "Deleting comment..."
2374
- })]
2375
- }) : jsxRuntime.jsx("div", {
2376
- className: "comment-list-items",
2377
- ref: commentEndRef,
2378
- children: comments.map((comment, index) => jsxRuntime.jsx("div", {
2379
- className: "comment-list-item",
2380
- children: jsxRuntime.jsx(CommentView, {
2381
- commentValue: comment[Constants.HAS_COMMENT_VALUE],
2382
- author: comment[Constants.HAS_AUTHOR] ? comment[Constants.HAS_AUTHOR] : null,
2383
- timestamp: comment[Constants.HAS_TIMESTAMP],
2384
- onDeleteQuestionComment: onDeleteCommentClick,
2385
- onDeleteViewComment: handleDeleteViewComment,
2386
- index: index
2387
- })
2388
- }, index))
2389
- })
2390
- });
2391
- };
2392
-
2393
- const ArrowRight = () => /*#__PURE__*/React__default["default"].createElement("svg", {
2394
- xmlns: "http://www.w3.org/2000/svg",
2395
- width: "15",
2396
- height: "15",
2397
- viewBox: "0 0 24 24"
2398
- }, /*#__PURE__*/React__default["default"].createElement("path", {
2399
- d: "M6.185 4.843l11.927 7.157-11.927 7.157 2.982-7.157-2.982-7.157zm-4.185-4.843l5 12-5 12 20-12-20-12z"
2400
- }));
2401
-
2402
- const MAX_TEXT_AREA_HEIGHT = "300px";
2403
- const CommentForm = props => {
2404
- const [commentValue, setCommentValue] = React.useState("");
2405
- const formInputRef = React.useRef(null);
2406
- const intl = reactIntl.useIntl();
2407
- React.useEffect(() => {
2408
- formInputRef.current.focus();
2409
- }, []);
2410
- const handleValueChange = e => {
2411
- setCommentValue(e.target.value);
2412
- };
2413
- const handleFormSubmit = e => {
2414
- e.preventDefault();
2415
- props.onChange(commentValue);
2416
- setCommentValue("");
2417
- };
2418
- const handleFormKeyUp = e => {
2419
- if (e.key === "Enter" && e.ctrlKey && commentValue.trim()) handleFormSubmit(e);
2420
- };
2421
- const handleFormClick = e => {
2422
- e.stopPropagation();
2423
- };
2424
- const handleTextAreaKeyPress = () => {
2425
- const textArea = formInputRef.current;
2426
- textArea.style.height = "auto";
2427
- autoResizeTextArea(textArea);
2428
- };
2429
- const autoResizeTextArea = textArea => {
2430
- let scrollHeight = textArea.scrollHeight;
2431
- textArea.style.height = `${scrollHeight}px`;
2432
- if (parseInt(textArea.style.height) > parseInt(MAX_TEXT_AREA_HEIGHT)) {
2433
- textArea.style.height = MAX_TEXT_AREA_HEIGHT;
2434
- }
2435
- };
2436
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form, {
2437
- onSubmit: handleFormSubmit,
2438
- onKeyUp: handleFormKeyUp,
2439
- onClick: handleFormClick
2440
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form.Group, {
2441
- className: "m-2",
2442
- controlId: "formBasicComment"
2443
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Col, {
2444
- className: "col-lg-12 p-0"
2445
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Row, {
2446
- className: "container-fluid p-0 m-0"
2447
- }, /*#__PURE__*/React__default["default"].createElement("div", {
2448
- id: "comment-form"
2449
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Form.Control, {
2450
- className: "comment-form-control",
2451
- name: "comment",
2452
- as: "textarea",
2453
- placeholder: intl.formatMessage({
2454
- id: "comment.form.placeholder"
2455
- }),
2456
- required: true,
2457
- value: commentValue,
2458
- onChange: handleValueChange,
2459
- ref: formInputRef,
2460
- onKeyPress: handleTextAreaKeyPress,
2461
- onKeyDown: handleTextAreaKeyPress
2462
- }), /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Button, {
2463
- className: "comment-form-button",
2464
- variant: "primary",
2465
- type: "submit"
2466
- }, /*#__PURE__*/React__default["default"].createElement(ArrowRight, null)))))));
2467
- };
2468
- CommentForm.propTypes = {
2469
- onChange: PropTypes__default["default"].func.isRequired
2470
- };
2471
-
2472
- const Close = () => /*#__PURE__*/React__default["default"].createElement("svg", {
2473
- className: "close-icon",
2474
- width: "24px",
2475
- height: "24px",
2476
- viewBox: "0 0 24 24",
2477
- xmlns: "http://www.w3.org/2000/svg"
2478
- }, /*#__PURE__*/React__default["default"].createElement("path", {
2479
- d: "M13.41 12l4.3-4.29a1 1 0 1 0-1.42-1.42L12 10.59l-4.29-4.3a1 1 0 0 0-1.42 1.42l4.3 4.29-4.3 4.29a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l4.29-4.3 4.29 4.3a1 1 0 0 0 1.42 0 1 1 0 0 0 0-1.42z"
2480
- }));
2481
-
2482
- const QuestionCommentIcon = props => {
2483
- const context = React.useContext(ConfigurationContext);
2484
- const target = React.useRef(null);
2485
- const dragRef = React.useRef(null);
2486
- const overlayTarget = React.useRef(null);
2487
- const [showOverlay, setShowOverlay] = React.useState(false);
2488
- const [overlayPlacement, setOverlayPlacement] = React.useState("right");
2489
- React.useEffect(() => {
2490
- getOverlayPlacement(overlayTarget.current);
2491
- });
2492
- const handleHideOverlayClick = () => {
2493
- setShowOverlay(false);
2494
- };
2495
-
2496
- // TODO make util function
2497
- const _getComments = () => {
2498
- const question = props.question;
2499
- if (!question[Constants.HAS_COMMENT]) {
2500
- question[Constants.HAS_COMMENT] = [];
2501
- }
2502
- if (!Array.isArray(question[Constants.HAS_COMMENT])) {
2503
- question[Constants.HAS_COMMENT] = [question[Constants.HAS_COMMENT]];
2504
- }
2505
- return question[Constants.HAS_COMMENT];
2506
- };
2507
- const handleCommentValueChange = value => {
2508
- const change = {};
2509
- _setComment(change, value);
2510
- props.onChange(getCommentsLength(), change);
2511
- };
2512
- const _setComment = (change, value) => {
2513
- if (context.options.currentUser) {
2514
- change[Constants.HAS_AUTHOR] = {
2515
- "@id": context.options.currentUser
2516
- };
2517
- }
2518
- change[Constants.HAS_COMMENT_VALUE] = value;
2519
- change[Constants.HAS_TIMESTAMP] = Date.now().toString();
2520
- };
2521
- const handleDeleteQuestionCommentClick = index => {
2522
- const comment = _getComments();
2523
- comment.splice(index, 1);
2524
- };
2525
- const handleStopPropagationClick = e => {
2526
- e.preventDefault();
2527
- e.stopPropagation();
2528
- };
2529
- const handleOverlayClick = e => {
2530
- handleStopPropagationClick(e);
2531
- setShowOverlay(!showOverlay);
2532
- };
2533
- const getCommentsLength = () => {
2534
- return _getComments().length;
2535
- };
2536
- const getOverlayPlacement = overlayTarget => {
2537
- if (!overlayTarget) return;
2538
- if (overlayTarget.getBoundingClientRect().x > window.innerWidth / 2) {
2539
- setOverlayPlacement("left");
2540
- } else setOverlayPlacement("right");
2541
- };
2542
- const handleEscapeKeyDown = e => {
2543
- if (e.key === "Escape") {
2544
- handleHideOverlayClick();
2545
- }
2546
- };
2547
- return /*#__PURE__*/React__default["default"].createElement("div", {
2548
- ref: overlayTarget,
2549
- onClick: handleStopPropagationClick
2550
- }, /*#__PURE__*/React__default["default"].createElement("span", {
2551
- className: "comment-bubble",
2552
- ref: target,
2553
- onClick: handleOverlayClick
2554
- }, /*#__PURE__*/React__default["default"].createElement(CommentBubble, null), getCommentsLength() > 0 ? /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Badge, {
2555
- className: "comment-badge",
2556
- pill: true,
2557
- variant: "primary"
2558
- }, getCommentsLength()) : null), /*#__PURE__*/React__default["default"].createElement(framerMotion.motion.div, {
2559
- className: "overlay-comment",
2560
- ref: dragRef,
2561
- drag: true,
2562
- dragConstraints: {
2563
- top: -50,
2564
- left: -50,
2565
- right: 50,
2566
- bottom: 50
2567
- }
2568
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Overlay, {
2569
- target: target.current,
2570
- show: showOverlay,
2571
- placement: overlayPlacement,
2572
- rootClose: false,
2573
- onHide: handleHideOverlayClick,
2574
- container: dragRef
2575
- }, overlayProps => /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Tooltip, _extends({
2576
- className: "comment-tooltip"
2577
- }, overlayProps), /*#__PURE__*/React__default["default"].createElement("span", {
2578
- onKeyDown: e => {
2579
- handleEscapeKeyDown(e);
2580
- }
2581
- }, /*#__PURE__*/React__default["default"].createElement(framerMotion.motion.div, {
2582
- className: "close-comment-icon",
2583
- onClick: handleHideOverlayClick,
2584
- whileHover: {
2585
- scale: 1.1,
2586
- transition: {
2587
- duration: 0.1
2588
- }
2589
- }
2590
- }, /*#__PURE__*/React__default["default"].createElement(Close, null)), /*#__PURE__*/React__default["default"].createElement(CommentList, {
2591
- comments: _getComments(),
2592
- onDeleteCommentClick: handleDeleteQuestionCommentClick
2593
- }), /*#__PURE__*/React__default["default"].createElement(CommentForm, {
2594
- onChange: handleCommentValueChange
2595
- }))))));
2596
- };
2597
- QuestionCommentIcon.propTypes = {
2598
- question: PropTypes__default["default"].object.isRequired,
2599
- onChange: PropTypes__default["default"].func.isRequired
2600
- };
2601
-
2602
- var _class;
2603
- class QuestionStatic {
2604
- static renderIcons(question, options, onCommentChange, showIcon) {
2605
- let icons;
2606
- if (options.icons) icons = options.icons;else icons = Constants.DEFAULT_OPTIONS.icons;
2607
- let iconsArray = [];
2608
- const renderQuestionHelp = this.renderQuestionHelp(question, options, onCommentChange, showIcon);
2609
- const renderQuestionComments = this.renderQuestionComments(question, options, onCommentChange, showIcon);
2610
- const renderQuestionLink = this.renderQuestionLink(question, options, onCommentChange, showIcon);
2611
- for (let i = 0; i < icons.length; i++) {
2612
- if (icons[i].id === Constants.ICONS.QUESTION_COMMENTS) {
2613
- iconsArray.push( /*#__PURE__*/React__default["default"].createElement("li", {
2614
- key: i,
2615
- className: "icon-list-item"
2616
- }, renderQuestionComments));
2617
- }
2618
- if (icons[i].id === Constants.ICONS.QUESTION_HELP) {
2619
- iconsArray.push( /*#__PURE__*/React__default["default"].createElement("li", {
2620
- key: i,
2621
- className: "icon-list-item"
2622
- }, renderQuestionHelp));
2623
- }
2624
- if (icons[i].id === Constants.ICONS.QUESTION_LINK) {
2625
- iconsArray.push( /*#__PURE__*/React__default["default"].createElement("li", {
2626
- key: i,
2627
- className: "icon-list-item"
2628
- }, renderQuestionLink));
2629
- }
2630
- }
2631
- return /*#__PURE__*/React__default["default"].createElement("ol", {
2632
- className: "icon-list-items"
2633
- }, iconsArray);
2634
- }
2635
- static renderQuestionHelp(question, options, onCommentChange, showIcon) {
2636
- return this.getIconComponentFromName(Constants.ICONS.QUESTION_HELP, question, options, onCommentChange, showIcon);
2637
- }
2638
- static renderQuestionLink(question, options, onCommentChange, showIcon) {
2639
- return this.getIconComponentFromName(Constants.ICONS.QUESTION_LINK, question, options, onCommentChange, showIcon);
2640
- }
2641
- static getIconComponentFromName(iconName, question, options, onCommentChange, showIcon) {
2642
- const iconList = options.icons ? options.icons : Constants.DEFAULT_OPTIONS.icons;
2643
- const icon = this.getIconFromIconList(iconList, iconName);
2644
- return this.getIconComponent(icon, question, options, onCommentChange, showIcon);
2645
- }
2646
- static getIconComponent(icon, question, options, onCommentChange, showIcon) {
2647
- let iconClassname;
2648
- if (icon && (icon.behavior === Constants.ICON_BEHAVIOR.ON_HOVER || icon.behavior === Constants.ICON_BEHAVIOR.ENABLE)) {
2649
- if (icon.behavior === Constants.ICON_BEHAVIOR.ENABLE) {
2650
- showIcon = true;
2651
- iconClassname = "";
2652
- } else iconClassname = "emphasise-on-relevant-icon";
2653
- if (icon.id === Constants.ICONS.QUESTION_HELP && question[Constants.HELP_DESCRIPTION]) {
2654
- if (showIcon) {
2655
- return /*#__PURE__*/React__default["default"].createElement("div", {
2656
- className: iconClassname
2657
- }, /*#__PURE__*/React__default["default"].createElement(HelpIcon, {
2658
- text: JsonLdUtils__default["default"].getLocalized(question[Constants.HELP_DESCRIPTION], options.intl),
2659
- absolutePosition: false
2660
- }));
2661
- }
2662
- return null;
2663
- }
2664
- if (icon.id === Constants.ICONS.QUESTION_LINK && question[Constants.SOURCE]) {
2665
- if (showIcon) {
2666
- return /*#__PURE__*/React__default["default"].createElement("div", {
2667
- className: iconClassname
2668
- }, /*#__PURE__*/React__default["default"].createElement(LinkIcon, {
2669
- url: question[Constants.SOURCE]
2670
- }));
2671
- }
2672
- return null;
2673
- }
2674
- if (icon.id === Constants.ICONS.QUESTION_COMMENTS) {
2675
- if (showIcon) {
2676
- return /*#__PURE__*/React__default["default"].createElement("div", {
2677
- className: iconClassname
2678
- }, /*#__PURE__*/React__default["default"].createElement(QuestionCommentIcon, {
2679
- question: question,
2680
- onChange: onCommentChange
2681
- }));
2682
- }
2683
- return null;
2684
- }
2685
- return null;
2686
- }
2687
- }
2688
- }
2689
- _class = QuestionStatic;
2690
- QuestionStatic.renderQuestionComments = (question, options, onCommentChange, showIcon) => {
2691
- return _class.getIconComponentFromName(Constants.ICONS.QUESTION_COMMENTS, question, options, onCommentChange, showIcon);
2692
- };
2693
- QuestionStatic.getIconFromIconList = (iconList, iconName) => {
2694
- if (iconList) return iconList.find(icon => icon.id === iconName);
2695
- return null;
2696
- };
2697
-
2698
- const Answer = props => {
2699
- const formGenContext = React__default["default"].useContext(FormGenContext);
2700
- const {
2701
- options
2702
- } = React__default["default"].useContext(ConfigurationContext);
2703
- const handleValueChange = value => {
2704
- const change = Object.assign({}, props.answer);
2705
- _setValue(change, value);
2706
- props.onChange(props.index, change);
2707
- };
2708
- const _setValue = (change, value) => {
2709
- if (value === null) {
2710
- change[Constants.HAS_OBJECT_VALUE] = null;
2711
- change[Constants.HAS_DATA_VALUE] = null;
2712
- } else if (props.answer[Constants.HAS_OBJECT_VALUE] || FormUtils.isTypeahead(props.question)) {
2713
- change[Constants.HAS_OBJECT_VALUE] = {
2714
- "@id": value
2715
- };
2716
- } else {
2717
- change[Constants.HAS_DATA_VALUE] = {
2718
- "@value": value
2719
- };
2720
- }
2721
- };
2722
- const _hasOptions = item => {
2723
- return item[Constants.HAS_OPTION] && item[Constants.HAS_OPTION].length !== 0;
2724
- };
2725
- const _renderTypeahead = (value, label, title) => {
2726
- const queryHash = Utils.getStringHash(FormUtils.getPossibleValuesQuery(props.question));
2727
- const options = formGenContext.getOptions(queryHash) || [];
2728
- return /*#__PURE__*/React__default["default"].createElement(TypeaheadAnswer, {
2729
- question: props.question,
2730
- answer: props.answer,
2731
- label: label,
2732
- title: title,
2733
- value: value,
2734
- onChange: handleValueChange,
2735
- options: options
2736
- });
2737
- };
2738
- const _renderSelect = (value, label, title) => {
2739
- return /*#__PURE__*/React__default["default"].createElement(SelectAnswer, {
2740
- question: props.question,
2741
- label: label,
2742
- title: title,
2743
- value: value,
2744
- onChange: handleValueChange
2745
- });
2746
- };
2747
- const _renderDateTimePicker = (value, label, title) => {
2748
- return /*#__PURE__*/React__default["default"].createElement(DateTimeAnswer, {
2749
- question: props.question,
2750
- value: value,
2751
- title: title,
2752
- label: label,
2753
- onChange: handleValueChange
2754
- });
2755
- };
2756
- const _renderCheckbox = (value, label, title) => {
2757
- return /*#__PURE__*/React__default["default"].createElement(CheckboxAnswer, {
2758
- label: label,
2759
- title: title,
2760
- value: value,
2761
- onChange: handleValueChange,
2762
- question: props.question
2763
- });
2764
- };
2765
- const _renderMaskedInput = (value, label, title) => {
2766
- return /*#__PURE__*/React__default["default"].createElement(MaskedInputAnswer, {
2767
- label: label,
2768
- title: title,
2769
- value: value,
2770
- onChange: handleValueChange,
2771
- question: props.question,
2772
- answer: props.answer
2773
- });
2774
- };
2775
- const _renderRegularInput = (value, label, title) => {
2776
- return /*#__PURE__*/React__default["default"].createElement(InputAnswer, {
2777
- question: props.question,
2778
- answer: props.answer,
2779
- label: label,
2780
- title: title,
2781
- value: value,
2782
- onChange: handleValueChange
2783
- });
2784
- };
2785
- const _renderSparqlInput = (value, label, title) => {
2786
- return /*#__PURE__*/React__default["default"].createElement(InputAnswer, {
2787
- question: props.question,
2788
- answer: props.answer,
2789
- label: label,
2790
- title: title,
2791
- value: value,
2792
- onChange: handleValueChange,
2793
- sparql: true
2794
- });
2795
- };
2796
- const _renderTurtleInput = (value, label, title) => {
2797
- return /*#__PURE__*/React__default["default"].createElement(InputAnswer, {
2798
- question: props.question,
2799
- answer: props.answer,
2800
- label: label,
2801
- title: title,
2802
- value: value,
2803
- onChange: handleValueChange,
2804
- turtle: true
2805
- });
2806
- };
2807
- const _getLabel = question => {
2808
- const label = JsonLdUtils__default["default"].getLocalized(question[Constants.RDFS_LABEL], options.intl);
2809
- return /*#__PURE__*/React__default["default"].createElement("div", {
2810
- className: "question-header"
2811
- }, label, QuestionStatic.renderIcons(props.question, options, props.onCommentChange, props.showIcon));
2812
- };
2813
- const question = props.question;
2814
- const value = FormUtils.resolveValue(props.answer);
2815
- const label = _getLabel(question);
2816
- const title = JsonLdUtils__default["default"].getLocalized(question[Constants.RDFS_COMMENT], options.intl);
2817
- let component;
2818
- if (FormUtils.isTypeahead(question)) {
2819
- component = _renderTypeahead(value, label, title);
2820
- } else if (_hasOptions(question)) {
2821
- component = _renderSelect(value, label, title);
2822
- } else if (FormUtils.isCalendar(question)) {
2823
- component = _renderDateTimePicker(value, label, title);
2824
- } else if (FormUtils.isCheckbox(question)) {
2825
- component = _renderCheckbox(value, label, title);
2826
- } else if (FormUtils.isMaskedInput(question)) {
2827
- component = _renderMaskedInput(value, label, title);
2828
- } else if (FormUtils.isSparqlInput(question)) {
2829
- component = _renderSparqlInput(value, label, title);
2830
- } else if (FormUtils.isTurtleInput(question)) {
2831
- component = _renderTurtleInput(value, label, title);
2832
- } else {
2833
- component = _renderRegularInput(value, label, title);
2834
- }
2835
- return component;
2836
- };
2837
- Answer.propTypes = {
2838
- answer: PropTypes__default["default"].object.isRequired,
2839
- question: PropTypes__default["default"].object.isRequired,
2840
- onChange: PropTypes__default["default"].func.isRequired,
2841
- onCommentChange: PropTypes__default["default"].func.isRequired,
2842
- index: PropTypes__default["default"].number,
2843
- icons: PropTypes__default["default"].object
2844
- };
2845
-
2846
- /**
2847
- * Created by blcha on 4.11.16.
2848
- */
2849
- class ValidatorFactory {
2850
- static createValidator(question, intl) {
2851
- if (question[Constants.REQUIRES_ANSWER]) {
2852
- if (FormUtils.isCheckbox(question)) {
2853
- //TODO revise
2854
- return ValidatorFactory._generateRequiresAnswerCheckBoxValidator(question, intl);
2855
- }
2856
- return ValidatorFactory._generateRequiresAnswerValidator(question, intl);
2857
- } else {
2858
- return () => {
2859
- const result = {};
2860
- result[Constants.HAS_VALID_ANSWER] = true;
2861
- delete result[Constants.HAS_VALIDATION_MESSAGE];
2862
- return result;
2863
- };
2864
- }
2865
- }
2866
- static _generateRequiresAnswerValidator(question, intl) {
2867
- return answer => {
2868
- let val = null;
2869
- if (answer[Constants.HAS_DATA_VALUE]) {
2870
- val = JsonLdUtils__default["default"].getJsonAttValue(answer, Constants.HAS_DATA_VALUE);
2871
- } else if (answer[Constants.HAS_OBJECT_VALUE]) {
2872
- val = JsonLdUtils__default["default"].getJsonAttValue(answer, Constants.HAS_OBJECT_VALUE, "@id");
2873
- }
2874
- const isValid = val !== null && val !== undefined && val !== "";
2875
- const result = {};
2876
- result[Constants.HAS_VALID_ANSWER] = isValid;
2877
- result[Constants.HAS_VALIDATION_MESSAGE] = isValid ? null : JsonLdUtils__default["default"].getLocalized(question[JsonLdUtils__default["default"].RDFS_LABEL], intl) + " is missing a value.";
2878
- return result;
2879
- };
2880
- }
2881
- static _generateRequiresAnswerCheckBoxValidator(question, intl) {
2882
- return answer => {
2883
- let val = null;
2884
- if (answer[Constants.HAS_DATA_VALUE]) {
2885
- val = JsonLdUtils__default["default"].getJsonAttValue(answer, Constants.HAS_DATA_VALUE);
2886
- } else if (answer[Constants.HAS_OBJECT_VALUE]) {
2887
- val = JsonLdUtils__default["default"].getJsonAttValue(answer, Constants.HAS_OBJECT_VALUE, "@id");
2888
- }
2889
- const isValid = val !== null && val !== undefined && val !== "" && val !== false;
2890
- const result = {};
2891
- result[Constants.HAS_VALID_ANSWER] = isValid;
2892
- result[Constants.HAS_VALIDATION_MESSAGE] = isValid ? null : JsonLdUtils__default["default"].getLocalized(question[JsonLdUtils__default["default"].RDFS_LABEL], intl) + " must be checked.";
2893
- return result;
2894
- };
2895
- }
2896
- }
2897
-
2898
- class PrefixIcon extends React__default["default"].Component {
2899
- constructor(props) {
2900
- super(props);
2901
- this.state = {
2902
- prefixes: props.prefixes
2903
- };
2904
- }
2905
- render() {
2906
- const p = /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Popover, {
2907
- id: "prefixes",
2908
- title: "Prefixes"
2909
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.ListGroup, null, this.state.prefixes.sort((l, r) => {
2910
- const res = l[Constants.PREFIX] < r[Constants.PREFIX];
2911
- if (res) return -1;
2912
- return 1;
2913
- }).map(p => /*#__PURE__*/React__default["default"].createElement(reactBootstrap.ListGroupItem, {
2914
- key: p[Constants.PREFIX]
2915
- }, /*#__PURE__*/React__default["default"].createElement("strong", null, p[Constants.PREFIX]), ": ", p[Constants.NAMESPACE]))));
2916
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.OverlayTrigger, {
2917
- trigger: "click",
2918
- placement: "right",
2919
- overlay: p
2920
- }, /*#__PURE__*/React__default["default"].createElement("span", {
2921
- className: this.props.iconClass
2922
- }, this.props.children));
2923
- }
2924
- }
2925
- PrefixIcon.propTypes = {
2926
- prefixes: PropTypes__default["default"].array.isRequired,
2927
- children: PropTypes__default["default"].element.isRequired,
2928
- iconClass: PropTypes__default["default"].string
2929
- };
2930
- PrefixIcon.defaultProps = {
2931
- iconClass: ""
2932
- };
2933
-
2934
- const MediaContent = ({
2935
- question
2936
- }) => {
2937
- const renderMedia = () => {
2938
- // @ts-ignore
2939
- const mediaContent = question[Constants.HAS_MEDIA_CONTENT];
2940
- if (mediaContent) {
2941
- if (Array.isArray(mediaContent)) {
2942
- return jsxRuntime.jsx("div", {
2943
- className: "col-6",
2944
- children: mediaContent.map((src, index) => jsxRuntime.jsx("div", {
2945
- className: "row embed-responsive-21by9 media-content-video-container mb-3",
2946
- children: jsxRuntime.jsx("iframe", {
2947
- src: mediaContent[index],
2948
- className: "embed-responsive-item",
2949
- allowFullScreen: true
2950
- })
2951
- }, index))
2952
- });
2953
- }
2954
- return jsxRuntime.jsx("div", {
2955
- className: "col-6",
2956
- children: jsxRuntime.jsx("iframe", {
2957
- src: mediaContent,
2958
- className: "embed-responsive-item",
2959
- allowFullScreen: true
2960
- })
2961
- });
2962
- }
2963
- return null;
2964
- };
2965
- return renderMedia();
2966
- };
2967
-
2968
- class Question extends React__default["default"].Component {
2969
- constructor(props) {
2970
- super(props);
2971
- this.handleAnswerChange = (answerIndex, change) => {
2972
- if (FormUtils.isSection(this.props.question)) {
2973
- let expanded = !!FormUtils.resolveValue(change);
2974
- this.setState({
2975
- expanded: expanded
2976
- });
2977
- }
2978
- this._handleChange(Constants.HAS_ANSWER, answerIndex, change);
2979
- };
2980
- this.handleSubQuestionChange = (subQuestionIndex, change) => {
2981
- this._handleChange(Constants.HAS_SUBQUESTION, subQuestionIndex, change);
2982
- };
2983
- this.handleCommentChange = (commentIndex, change) => {
2984
- this._handleChange(Constants.HAS_COMMENT, commentIndex, change);
2985
- };
2986
- this._toggleCollapse = () => {
2987
- if (this.props.collapsible) {
2988
- this.setState({
2989
- expanded: !this.state.expanded
2990
- });
2991
- }
2992
- };
2993
- this._onMouseEnterHandler = () => {
2994
- this.setState({
2995
- showIcon: true
2996
- });
2997
- };
2998
- this._onMouseLeaveHandler = () => {
2999
- this.setState({
3000
- showIcon: false
3001
- });
3002
- };
3003
- this._getHeaderClassName = () => {
3004
- const question = this.props.question;
3005
- const collapsible = this.props.collapsible;
3006
- let headerClassName = [];
3007
- headerClassName.push(Question.getEmphasizedOnRelevantClass(question), "question-header");
3008
- if (FormUtils.isWizardStep(question)) headerClassName.push("wizard-step bg-primary text-white");
3009
- if (FormUtils.isEmphasised(question)) headerClassName.push(Question.getEmphasizedClass(question));
3010
- if (FormUtils.isSection(question)) headerClassName.push("section-background");
3011
- if (collapsible) headerClassName.push("cursor-pointer");
3012
- if (this.isDebugged(question)) {
3013
- headerClassName.push("show-irrelevant");
3014
- }
3015
- return headerClassName;
3016
- };
3017
- JsonLdObjectMap.putObject(props.question["@id"], props.question);
3018
- this.state = {
3019
- validator: null,
3020
- expanded: !FormUtils.isCollapsed(props.question),
3021
- showIcon: false
3022
- };
3023
- }
3024
- componentDidMount() {
3025
- this.setState({
3026
- validator: ValidatorFactory.createValidator(this.props.question, this.context.options.intl)
3027
- });
3028
- }
3029
- componentDidUpdate() {
3030
- const question = this.props.question;
3031
- const startingQuestionId = this.context.options.startingQuestionId;
3032
- const subQuestions = question[Constants.HAS_SUBQUESTION];
3033
- const isSubQuestionStartingQuestionId = subQuestions.find(o => o["@id"] === startingQuestionId);
3034
- if (FormUtils.isSection(question) && FormUtils.isAnswerable(question)) {
3035
- const answerValue = this._getFirstAnswerValue();
3036
-
3037
- // Irrelevant questions are expanded if debugMode is on
3038
- if (this.context.options.debugMode) {
3039
- return null;
3040
- }
3041
- if (isSubQuestionStartingQuestionId) {
3042
- return null;
3043
- } else if (this.state.expanded && !answerValue) {
3044
- // close expanded answerable section that does not have positive answer
3045
- this.setState({
3046
- expanded: false
3047
- });
3048
- }
3049
- }
3050
- }
3051
- _handleChange(att, valueIndex, newValue) {
3052
- let newState = Object.assign({}, this.props.question);
3053
- newState[att][valueIndex] = newValue;
3054
- if (att === Constants.HAS_ANSWER) {
3055
- const result = this.state.validator(newValue);
3056
- newState = Object.assign({}, newState, result);
3057
- }
3058
- JsonLdObjectMap.putObject(newState["@id"], newState);
3059
- this.props.onChange(this.props.index, newState);
3060
- }
3061
- isDebugged(question) {
3062
- const startingQuestionId = this.context.options.startingQuestionId;
3063
- if (FormUtils.isRelevant(question)) {
3064
- return false;
3065
- }
3066
- if (this.context.options.debugMode) {
3067
- return true;
3068
- }
3069
- if (startingQuestionId == null) {
3070
- return false;
3071
- }
3072
- let questionById = Utils.findQuestionById(startingQuestionId, question, true, false, false);
3073
- return !!questionById;
3074
- }
3075
- render() {
3076
- const question = this.props.question;
3077
- const questionComponent = this.renderQuestion(question);
3078
- if (this.isDebugged(question)) {
3079
- return /*#__PURE__*/React__default["default"].createElement("div", {
3080
- className: "show-irrelevant"
3081
- }, questionComponent);
3082
- }
3083
- if (FormUtils.isHidden(question)) {
3084
- return null;
3085
- }
3086
- if (!FormUtils.isRelevant(question)) {
3087
- return null;
3088
- }
3089
- return questionComponent;
3090
- }
3091
- renderQuestion(question) {
3092
- if (FormUtils.isAnswerable(question) && !FormUtils.isSection(question)) {
3093
- {
3094
- return /*#__PURE__*/React__default["default"].createElement("div", {
3095
- id: question["@id"]
3096
- }, /*#__PURE__*/React__default["default"].createElement("div", {
3097
- className: "panel-title answerable-question"
3098
- }, this.renderAnswers()), /*#__PURE__*/React__default["default"].createElement("div", {
3099
- className: "answerable-subquestions"
3100
- }, this.renderSubQuestions()));
3101
- }
3102
- }
3103
- if (FormUtils.isAnswerable(question)) {
3104
- return this.renderAnswerableSection();
3105
- }
3106
- if (FormUtils.isSection(question)) {
3107
- const {
3108
- collapsible,
3109
- withoutCard
3110
- } = this.props;
3111
- const categoryClass = Question._getQuestionCategoryClass(question);
3112
- if (withoutCard) {
3113
- return /*#__PURE__*/React__default["default"].createElement("div", null, this._renderQuestionContent());
3114
- }
3115
- const label = JsonLdUtils__default["default"].getLocalized(question[JsonLdUtils__default["default"].RDFS_LABEL], this.context.options.intl);
3116
- const cardBody = /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Card.Body, {
3117
- className: classNames__default["default"]("p-3", categoryClass)
3118
- }, this._renderQuestionContent());
3119
- return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Accordion, {
3120
- defaultActiveKey: !this.state.expanded ? label : undefined
3121
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Card, {
3122
- className: "mb-3"
3123
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Accordion.Toggle, {
3124
- as: reactBootstrap.Card.Header,
3125
- onClick: this._toggleCollapse,
3126
- className: this._getHeaderClassName(),
3127
- onMouseEnter: this._onMouseEnterHandler,
3128
- onMouseLeave: this._onMouseLeaveHandler
3129
- }, /*#__PURE__*/React__default["default"].createElement("h6", {
3130
- className: "d-inline",
3131
- id: question["@id"]
3132
- }, collapsible && !FormUtils.isWizardStep(question) && this._renderCollapseToggle(), label), this.renderQuestionIcons(), this.props.children), collapsible ? /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Accordion.Collapse, null, cardBody) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, cardBody))));
3133
- } else {
3134
- return /*#__PURE__*/React__default["default"].createElement("div", null, this._renderQuestionContent());
3135
- }
3136
- }
3137
- _renderQuestionContent() {
3138
- let content = [];
3139
- if (this.state.expanded) {
3140
- content.push( /*#__PURE__*/React__default["default"].createElement(MediaContent, {
3141
- key: this.props.question["@id"] + "-media",
3142
- question: this.props.question
3143
- }));
3144
- }
3145
- content.push(this.renderAnswers());
3146
- content.push(this.renderSubQuestions());
3147
- return content;
3148
- }
3149
- renderQuestionIcons() {
3150
- const question = this.props.question;
3151
- const options = this.context.options;
3152
- return QuestionStatic.renderIcons(question, options, this.handleCommentChange, this.state.showIcon);
3153
- }
3154
- renderAnswerableSection() {
3155
- const question = this.props.question;
3156
- const collapsible = this.props.collapsible;
3157
- const categoryClass = Question._getQuestionCategoryClass(question);
3158
- let classname = this.getShowIrrelevantClassname(question);
3159
- const cardBody = /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Card.Body, {
3160
- className: classNames__default["default"]("p-3", categoryClass)
3161
- }, this.renderSubQuestions(classname));
3162
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Accordion, {
3163
- activeKey: this.state.expanded ? question["@id"] : undefined,
3164
- className: "answerable-section"
3165
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Card, {
3166
- className: "mb-3"
3167
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Card.Header, {
3168
- onClick: this._toggleCollapse,
3169
- className: this._getHeaderClassName()
3170
- }, this.renderAnswers()), collapsible ? /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Accordion.Collapse, {
3171
- className: classname,
3172
- eventKey: question["@id"]
3173
- }, cardBody) : {
3174
- cardBody
3175
- }));
3176
- }
3177
- getShowIrrelevantClassname(question) {
3178
- const debugMode = this.context.options.debugMode;
3179
- const startingQuestionId = this.context.options.startingQuestionId;
3180
- const subQuestion = question[Constants.HAS_SUBQUESTION];
3181
- if ((debugMode || JsonLdObjectUtils.checkId(subQuestion, startingQuestionId)) && !FormUtils.hasAnswer(question)) {
3182
- return "show-irrelevant";
3183
- }
3184
- return "";
3185
- }
3186
- renderAnswers() {
3187
- const question = this.props.question,
3188
- children = [],
3189
- answers = this._getAnswers();
3190
- let cls;
3191
- for (let i = 0, len = answers.length; i < len; i++) {
3192
- FormUtils.isTextarea(question, FormUtils.resolveValue(answers[i])) || FormUtils.isSparqlInput(question) || FormUtils.isTurtleInput(question);
3193
- cls = classNames__default["default"]("answer", Question._getQuestionCategoryClass(question), Question.getEmphasizedOnRelevantClass(question));
3194
- children.push( /*#__PURE__*/React__default["default"].createElement("div", {
3195
- key: "row-item-" + i,
3196
- className: cls,
3197
- id: question["@id"],
3198
- onMouseEnter: this._onMouseEnterHandler,
3199
- onMouseLeave: this._onMouseLeaveHandler
3200
- }, /*#__PURE__*/React__default["default"].createElement("div", {
3201
- className: "answer-content",
3202
- style: this._getAnswerWidthStyle()
3203
- }, /*#__PURE__*/React__default["default"].createElement(Answer, {
3204
- index: i,
3205
- answer: answers[i],
3206
- question: question,
3207
- onChange: this.handleAnswerChange,
3208
- onCommentChange: this.handleCommentChange,
3209
- showIcon: this.state.showIcon
3210
- })), this._renderUnits(), this._renderPrefixes()));
3211
- }
3212
- return children;
3213
- }
3214
- _getAnswers() {
3215
- const question = this.props.question;
3216
- if (!question[Constants.HAS_ANSWER]) {
3217
- question[Constants.HAS_ANSWER] = [];
3218
- }
3219
- if (!Array.isArray(question[Constants.HAS_ANSWER])) {
3220
- question[Constants.HAS_ANSWER] = [question[Constants.HAS_ANSWER]];
3221
- }
3222
- if (question[Constants.HAS_ANSWER].length === 0) {
3223
- if (FormUtils.isSection(question) && !FormUtils.isAnswerable(question)) {
3224
- question[Constants.HAS_ANSWER] = [];
3225
- } else {
3226
- question[Constants.HAS_ANSWER] = [QuestionAnswerProcessor.generateAnswer(question)];
3227
- }
3228
- }
3229
- return question[Constants.HAS_ANSWER];
3230
- }
3231
- _getAnswerWidthStyle() {
3232
- const length = Number(this.props.question[Constants.HAS_INITIAL_INPUT_LENGTH]);
3233
- if (!length) {
3234
- return {};
3235
- }
3236
- return {
3237
- flexGrow: 0,
3238
- maxWidth: "none",
3239
- width: `calc(${length}ch + 1.5rem + 2px)`
3240
- };
3241
- }
3242
- static _getAnswerClass(question, isTextarea) {
3243
- let columns = isTextarea ? "col-12" : Constants.GENERATED_ROW_SIZE === 1 ? "col-6" : "col-" + Constants.COLUMN_COUNT / Constants.GENERATED_ROW_SIZE;
3244
- return columns;
3245
- }
3246
- static _getQuestionCategoryClass(question) {
3247
- const layoutCategory = FormUtils.getCategory(question);
3248
- return layoutCategory ? "question-" + layoutCategory : "";
3249
- }
3250
- static getEmphasizedClass(question) {
3251
- return FormUtils.isEmphasised(question) ? "bg-warning" : "";
3252
- }
3253
- static getEmphasizedOnRelevantClass(question) {
3254
- if (JsonLdUtils__default["default"].hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.EMPHASISE_ON_RELEVANT)) {
3255
- return "emphasise-on-relevant";
3256
- }
3257
- return "";
3258
- }
3259
- _renderCollapseToggle() {
3260
- const {
3261
- options
3262
- } = this.context;
3263
- const title = this.state.expanded ? options.i18n["section.collapse"] : options.i18n["section.expand"];
3264
- return /*#__PURE__*/React__default["default"].createElement("span", {
3265
- onClick: this._toggleCollapse,
3266
- title: title
3267
- }, this.state.expanded ? /*#__PURE__*/React__default["default"].createElement(CaretSquareUp, {
3268
- title: title
3269
- }) : /*#__PURE__*/React__default["default"].createElement(CaretSquareDown, {
3270
- title: title
3271
- }));
3272
- }
3273
- _renderPrefixes() {
3274
- const question = this.props.question;
3275
- return question[Constants.HAS_DECLARED_PREFIX] && question[Constants.HAS_DECLARED_PREFIX].length ? /*#__PURE__*/React__default["default"].createElement(PrefixIcon, {
3276
- prefixes: question[Constants.HAS_DECLARED_PREFIX],
3277
- iconClass: "help-icon-checkbox"
3278
- }, /*#__PURE__*/React__default["default"].createElement(InfoCircle, null)) : null;
3279
- }
3280
- _renderUnits() {
3281
- const question = this.props.question;
3282
- return question[Constants.HAS_UNIT] ? /*#__PURE__*/React__default["default"].createElement("div", {
3283
- className: "has-unit-label"
3284
- }, question[Constants.HAS_UNIT]) : null;
3285
- }
3286
- renderSubQuestions(classname) {
3287
- const children = [];
3288
- const subQuestions = this._getSubQuestions();
3289
- const debugMode = this.context.options.debugMode;
3290
- const startingQuestionId = this.context.options.startingQuestionId;
3291
- for (let i = 0; i < subQuestions.length; i++) {
3292
- let question = subQuestions[i];
3293
- let component = this.context.mapComponent(question, Question);
3294
- let element = null;
3295
- if (debugMode || classname !== "show-irrelevant" || Utils.findQuestionById(startingQuestionId, question, true, false, false)) {
3296
- element = /*#__PURE__*/React__default["default"].createElement(component, {
3297
- key: "sub-question-" + i,
3298
- question: question,
3299
- onChange: this.handleSubQuestionChange,
3300
- index: i
3301
- });
3302
- }
3303
- children.push(element);
3304
- }
3305
- return children;
3306
- }
3307
- _getSubQuestions() {
3308
- const question = this.props.question;
3309
- if (!question[Constants.HAS_SUBQUESTION]) {
3310
- question[Constants.HAS_SUBQUESTION] = [];
3311
- }
3312
- if (!Array.isArray(question[Constants.HAS_SUBQUESTION])) {
3313
- question[Constants.HAS_SUBQUESTION] = [question[Constants.HAS_SUBQUESTION]];
3314
- }
3315
-
3316
- // sort by label
3317
- JsonLdObjectUtils.orderByLocalizedLabels(question[Constants.HAS_SUBQUESTION], this.context.options.intl);
3318
-
3319
- // sort by property
3320
- JsonLdObjectUtils.orderPreservingToplogicalSort(question[Constants.HAS_SUBQUESTION], Constants.HAS_PRECEDING_QUESTION);
3321
- return question[Constants.HAS_SUBQUESTION];
3322
- }
3323
- _getFirstAnswerValue() {
3324
- return FormUtils.resolveValue(this._getAnswers()[0]);
3325
- }
3326
- }
3327
- Question.contextType = ConfigurationContext;
3328
- Question.propTypes = {
3329
- question: PropTypes__default["default"].object.isRequired,
3330
- onChange: PropTypes__default["default"].func.isRequired,
3331
- index: PropTypes__default["default"].number,
3332
- withoutCard: PropTypes__default["default"].bool,
3333
- collapsible: PropTypes__default["default"].bool // Whether the section is collapsible (if the question is a section)
3334
- };
3335
-
3336
- Question.defaultProps = {
3337
- withoutCard: false,
3338
- collapsible: true
3339
- };
3340
-
3341
- class WizardStep extends React__default["default"].Component {
3342
- constructor(props) {
3343
- super(props);
3344
- this.onNextStep = () => {
3345
- this.context.updateFormQuestionsData(this.props.index, this.context.getFormQuestionsData());
3346
- this.props.onNextStep();
3347
- };
3348
- this.onPreviousStep = () => {
3349
- this.props.onPreviousStep();
3350
- };
3351
- this._renderWizardStepButtons = () => {
3352
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.ButtonToolbar, {
3353
- className: "m-3 float-right"
3354
- }, !this.props.isFirstStep && /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Button, {
3355
- className: "mr-2",
3356
- onClick: this.onPreviousStep,
3357
- variant: "primary",
3358
- size: "sm"
3359
- }, this.props.options.i18n["wizard.previous"]), !this.props.isLastStep && /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Button, {
3360
- onClick: this.onNextStep,
3361
- variant: "primary",
3362
- size: "sm"
3363
- }, this.props.options.i18n["wizard.next"]));
3364
- };
3365
- this.onChange = (index, change) => {
3366
- this.context.updateFormQuestionsData(this.props.index || index, Object.assign({}, this.props.question, change));
3367
- };
3368
- }
3369
- render() {
3370
- const question = this.context.getFormQuestionsData([this.props.index]);
3371
- return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(Question, {
3372
- question: question,
3373
- onChange: this.onChange,
3374
- collapsible: FormUtils.isAnswerable(question)
3375
- }), this.props.options.wizardStepButtons && this._renderWizardStepButtons());
3376
- }
3377
- }
3378
- WizardStep.propTypes = {
3379
- options: PropTypes__default["default"].object.isRequired,
3380
- question: PropTypes__default["default"].object.isRequired,
3381
- index: PropTypes__default["default"].number.isRequired,
3382
- onNextStep: PropTypes__default["default"].func,
3383
- onPreviousStep: PropTypes__default["default"].func,
3384
- mapComponent: PropTypes__default["default"].func,
3385
- isFirstStep: PropTypes__default["default"].bool,
3386
- isLastStep: PropTypes__default["default"].bool
3387
- };
3388
- WizardStep.contextType = FormQuestionsContext;
3389
-
3390
- const HorizontalWizardNav = ({
3391
- steps,
3392
- onNavigate,
3393
- currentStep
3394
- }) => {
3395
- const {
3396
- options
3397
- } = React.useContext(ConfigurationContext);
3398
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Card.Header, null, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Nav, {
3399
- variant: "tabs",
3400
- activeKey: currentStep,
3401
- onSelect: key => onNavigate(parseInt(key))
3402
- }, steps.map((step, index) => /*#__PURE__*/React__default["default"].createElement(reactBootstrap.NavItem, {
3403
- key: "nav" + index,
3404
- id: "wizard-nav-" + index
3405
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.NavLink, {
3406
- eventKey: index,
3407
- active: index === currentStep ? "active" : "",
3408
- hidden: options.debugMode ? false : !FormUtils.isRelevant(step),
3409
- className: classNames__default["default"]([options.debugMode && !FormUtils.isRelevant(step) ? "show-irrelevant" : Question.getEmphasizedClass(step), "wizard-nav"])
3410
- }, JsonLdUtils__default["default"].getLocalized(step[JsonLdUtils__default["default"].RDFS_LABEL], options.intl))))));
3411
- };
3412
- HorizontalWizardNav.propTypes = {
3413
- currentStep: PropTypes__default["default"].number.isRequired,
3414
- steps: PropTypes__default["default"].array.isRequired,
3415
- onNavigate: PropTypes__default["default"].func.isRequired
3416
- };
3417
-
3418
- const VerticalWizardNav = ({
3419
- steps,
3420
- onNavigate,
3421
- currentStep
3422
- }) => {
3423
- const {
3424
- options
3425
- } = React.useContext(ConfigurationContext);
3426
- return /*#__PURE__*/React__default["default"].createElement("div", {
3427
- className: "wizard-nav col-2 p-0"
3428
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.ListGroup, null, steps.map((step, index) => /*#__PURE__*/React__default["default"].createElement(reactBootstrap.ListGroupItem, {
3429
- hidden: options.debugMode ? false : !FormUtils.isRelevant(step),
3430
- key: "nav" + index,
3431
- onClick: () => onNavigate(index),
3432
- id: "wizard-nav-" + index,
3433
- action: true,
3434
- active: index === currentStep ? "active" : "",
3435
- variant: "default",
3436
- className: classNames__default["default"]([options.debugMode && !FormUtils.isRelevant(step) ? "show-irrelevant" : Question.getEmphasizedClass(step), "wizard-nav"])
3437
- }, JsonLdUtils__default["default"].getLocalized(step[JsonLdUtils__default["default"].RDFS_LABEL], options.intl)))));
3438
- };
3439
- VerticalWizardNav.propTypes = {
3440
- currentStep: PropTypes__default["default"].number.isRequired,
3441
- steps: PropTypes__default["default"].array.isRequired,
3442
- onNavigate: PropTypes__default["default"].func.isRequired
3443
- };
3444
-
3445
- const findStepByQuestionId = (stepData, id) => {
3446
- const findQuestionTraversal = (question, index) => {
3447
- if (!question) {
3448
- return -1;
3449
- }
3450
- if (question["@id"] === id) {
3451
- return index;
3452
- }
3453
- const subQuestions = Utils.asArray(question[Constants.HAS_SUBQUESTION]);
3454
- return subQuestions.findIndex((q, index) => findQuestionTraversal(q, index) !== -1);
3455
- };
3456
- return stepData.findIndex((step, index) => findQuestionTraversal(step, index) !== -1);
3457
- };
3458
- const Wizard = () => {
3459
- const formQuestionsContext = React__default["default"].useContext(FormQuestionsContext);
3460
- const {
3461
- options,
3462
- mapComponent
3463
- } = React__default["default"].useContext(ConfigurationContext);
3464
- let startingStep = 0;
3465
- if (options.startingQuestionId) {
3466
- startingStep = findStepByQuestionId(formQuestionsContext.getFormQuestionsData(), options.startingQuestionId);
3467
- if (startingStep === -1) {
3468
- console.warn(`Question with id ${options.startingQuestionId} not found!`);
3469
- startingStep = 0;
3470
- }
3471
- } else if (options.startingStep) {
3472
- startingStep = options.startingStep < formQuestionsContext.getFormQuestionsData().length ? options.startingStep : 0;
3473
- }
3474
- const [currentStep, setCurrentStep] = React__default["default"].useState(startingStep);
3475
- const [scrolledToStartingQuestionId, setScrolledToStartingQuestionId] = React__default["default"].useState(false);
3476
- React.useEffect(() => {
3477
- if (options.startingQuestionId && !scrolledToStartingQuestionId) {
3478
- const element = document.getElementById(options.startingQuestionId);
3479
- if (element) {
3480
- element.scrollIntoView();
3481
- element.classList.add("text-danger");
3482
- setScrolledToStartingQuestionId(true);
3483
- }
3484
- }
3485
- });
3486
- const onNextStep = () => {
3487
- const stepData = formQuestionsContext.getFormQuestionsData();
3488
- if (currentStep !== stepData.length - 1) {
3489
- stepData[currentStep + 1].visited = true;
3490
- setCurrentStep(prevCurrentStep => prevCurrentStep + 1);
3491
- }
3492
- };
3493
- const onPreviousStep = () => {
3494
- if (currentStep === 0) {
3495
- return;
3496
- }
3497
- setCurrentStep(prevCurrentStep => prevCurrentStep - 1);
3498
- };
3499
- const navigate = stepIndex => {
3500
- const stepData = formQuestionsContext.getFormQuestionsData();
3501
- if (stepIndex === currentStep || stepIndex >= stepData.length) {
3502
- return;
3503
- }
3504
- // Can we jump forward?
3505
- if (stepIndex > currentStep && !stepData[stepIndex].visited && !options.enableForwardSkip) {
3506
- return;
3507
- }
3508
- setCurrentStep(stepIndex);
3509
- };
3510
- const renderNav = () => {
3511
- const formQuestionsData = formQuestionsContext.getFormQuestionsData();
3512
- return options.horizontalWizardNav ? /*#__PURE__*/React__default["default"].createElement(HorizontalWizardNav, {
3513
- currentStep: currentStep,
3514
- steps: formQuestionsData,
3515
- onNavigate: navigate
3516
- }) : /*#__PURE__*/React__default["default"].createElement(VerticalWizardNav, {
3517
- currentStep: currentStep,
3518
- steps: formQuestionsData,
3519
- onNavigate: navigate
3520
- });
3521
- };
3522
- const initComponent = () => {
3523
- const stepData = formQuestionsContext.getFormQuestionsData();
3524
- const step = stepData[currentStep];
3525
- let stepComponent = mapComponent(step, WizardStep);
3526
- return /*#__PURE__*/React__default["default"].createElement(stepComponent, {
3527
- options: options,
3528
- key: "step" + currentStep,
3529
- question: step,
3530
- onNextStep: onNextStep,
3531
- onPreviousStep: onPreviousStep,
3532
- mapComponent: mapComponent,
3533
- index: currentStep,
3534
- isFirstStep: currentStep === 0,
3535
- isLastStep: currentStep === formQuestionsContext.getFormQuestionsData().length - 1
3536
- });
3537
- };
3538
- let nav = null;
3539
- if (formQuestionsContext.getFormQuestionsData().length > 1) {
3540
- nav = renderNav();
3541
- }
3542
- const isHorizontal = options.horizontalWizardNav;
3543
- const cardClassname = isHorizontal ? "" : "flex-row p-3";
3544
- const containerClassname = isHorizontal ? "card-body p-3" : nav ? "col-10 p-0 pl-3" : "col-12 p-0";
3545
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Card, {
3546
- className: cardClassname
3547
- }, nav, /*#__PURE__*/React__default["default"].createElement("div", {
3548
- className: containerClassname
3549
- }, initComponent()));
3550
- };
3551
-
3552
- const FormWindow = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
3553
- const {
3554
- options
3555
- } = React__default["default"].useContext(ConfigurationContext);
3556
- return /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Modal, _extends({
3557
- size: "xl",
3558
- animation: true
3559
- }, options.modalProps), /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Modal.Header, {
3560
- closeButton: true
3561
- }, /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Modal.Title, null, options.modalProps.title)), /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Modal.Body, {
3562
- className: "overflow-hidden p-0"
3563
- }, props.children));
3564
- });
3565
- FormWindow.propTypes = {
3566
- children: PropTypes__default["default"].element.isRequired
3567
- };
3568
-
3569
- class FormManager extends React__default["default"].Component {
3570
- constructor(...args) {
3571
- super(...args);
3572
- this.getFormData = () => {
3573
- const data = this.context.getData();
3574
- const formQuestionsData = this.context.getFormQuestionsData();
3575
- return QuestionAnswerProcessor.buildQuestionAnswerModel(data, formQuestionsData);
3576
- };
3577
- this.getFormQuestionsData = () => {
3578
- return this.context.getFormQuestionsData();
3579
- };
3580
- this.handleStepChange = (question, index, change) => {
3581
- this.context.updateFormQuestionsData(index, Object.assign({}, question, change));
3582
- };
3583
- this.renderWizardlessForm = () => {
3584
- const formQuestionsData = this.context.getFormQuestionsData();
3585
- return /*#__PURE__*/React__default["default"].createElement(Card__default["default"], {
3586
- className: "p-3"
3587
- }, formQuestionsData.map((q, i) => this._mapQuestion(q, i)));
3588
- };
3589
- }
3590
- _mapQuestion(question, index) {
3591
- let component = this.props.mapComponent(question, Question);
3592
- return /*#__PURE__*/React__default["default"].createElement(component, {
3593
- key: question["@id"],
3594
- question: question,
3595
- onChange: (index, change) => this.handleStepChange(question, index, change),
3596
- index: index
3597
- });
3598
- }
3599
- render() {
3600
- const {
3601
- modalView
3602
- } = this.props;
3603
- const formQuestionsData = this.context.getFormQuestionsData();
3604
- if (!formQuestionsData.length) {
3605
- return /*#__PURE__*/React__default["default"].createElement(Card__default["default"], {
3606
- className: "p-3 font-italic"
3607
- }, "There are no questions available...");
3608
- }
3609
- const isWizardless = formQuestionsData.every(question => !FormUtils.isWizardStep(question));
3610
- if (modalView) {
3611
- return /*#__PURE__*/React__default["default"].createElement(FormWindow, null, isWizardless ? this.renderWizardlessForm() : /*#__PURE__*/React__default["default"].createElement(Wizard, null));
3612
- }
3613
- return isWizardless ? this.renderWizardlessForm() : /*#__PURE__*/React__default["default"].createElement(Wizard, null);
3614
- }
3615
- }
3616
- FormManager.contextType = FormQuestionsContext;
3617
-
3618
- const SForms = /*#__PURE__*/React.forwardRef((props, ref) => {
3619
- const [loading, setLoading] = React.useState(true);
3620
- const [formProperties, setFormProperties] = React.useState(null);
3621
- const [form, setForm] = React.useState(null);
3622
- React.useEffect(() => {
3623
- const initialiseSForms = async () => {
3624
- const intl = props.options.intl;
3625
- const [formProperties, structure] = await FormGenerator.constructForm(props.form, intl);
3626
- if (formProperties.formQuestions.some(step => FormUtils.isWizardStep(step))) {
3627
- formProperties.formQuestions[0].visited = true;
3628
- }
3629
- setFormProperties(formProperties);
3630
- setForm(structure);
3631
- setLoading(false);
3632
- };
3633
- initialiseSForms();
3634
- }, [props.form]);
3635
- if (loading) {
3636
- return props.loader || /*#__PURE__*/React__default["default"].createElement(reactBootstrap.Card, {
3637
- className: "p-3 font-italic"
3638
- }, "Loading SForms...");
3639
- }
3640
- const _getComponentMappingFunction = (components, form) => {
3641
- return (question, defaultComponent) => {
3642
- if (!components) {
3643
- return defaultComponent;
3644
- }
3645
- for (let {
3646
- component,
3647
- mapRule
3648
- } of components) {
3649
- if (mapRule(question, form)) {
3650
- return component;
3651
- }
3652
- }
3653
- return defaultComponent;
3654
- };
3655
- };
3656
- const _mapComponent = _getComponentMappingFunction(props.componentMapRules, form);
3657
- return /*#__PURE__*/React__default["default"].createElement(ConfigurationContextProvider, {
3658
- components: props.components,
3659
- componentsOptions: props.componentsOptions,
3660
- mapComponent: _mapComponent,
3661
- options: props.options
3662
- }, /*#__PURE__*/React__default["default"].createElement(FormGenContextProvider, {
3663
- fetchTypeAheadValues: props.fetchTypeAheadValues
3664
- }, /*#__PURE__*/React__default["default"].createElement(FormQuestionsProvider, {
3665
- data: form,
3666
- formQuestions: formProperties.formQuestions,
3667
- isFormValid: props.isFormValid
3668
- }, /*#__PURE__*/React__default["default"].createElement(FormManager, {
3669
- ref: ref,
3670
- modalView: props.options && props.options.modalView,
3671
- mapComponent: _mapComponent
3672
- }))));
3673
- });
3674
- SForms.propTypes = {
3675
- form: PropTypes__default["default"].object.isRequired,
3676
- options: PropTypes__default["default"].object.isRequired,
3677
- componentMapRules: PropTypes__default["default"].array,
3678
- components: PropTypes__default["default"].object,
3679
- componentsOptions: PropTypes__default["default"].object,
3680
- fetchTypeAheadValues: PropTypes__default["default"].func,
3681
- isFormValid: PropTypes__default["default"].func,
3682
- loader: PropTypes__default["default"].element
3683
- };
3684
-
3685
- var cs = {
3686
- "comment.form.placeholder": "Sem napište své komentáře (Ctrl+Enter pro potvrzení)"
3687
- };
3688
-
3689
- var en = {
3690
- "comment.form.placeholder": "Write your comments here (Ctrl+Enter to confirm, Esc to cancel)"
3691
- };
3692
-
3693
- const IntlContext = /*#__PURE__*/React__default["default"].createContext({});
3694
- const IntlContextProvider = ({
3695
- children,
3696
- locale = navigator.language
3697
- }) => {
3698
- let lang = en;
3699
- if (locale === Constants.LANG.cs.locale) {
3700
- lang = cs;
3701
- }
3702
- return jsxRuntime.jsx(IntlContext.Provider, {
3703
- value: {
3704
- locale,
3705
- lang
3706
- },
3707
- children: jsxRuntime.jsx(reactIntl.IntlProvider, {
3708
- locale: locale,
3709
- messages: lang,
3710
- children: children
3711
- })
3712
- });
3713
- };
3714
-
3715
- exports.Answer = Answer;
3716
- exports.ConfigurationContext = ConfigurationContext;
3717
- exports.Constants = Constants;
3718
- exports.FormQuestionsContext = FormQuestionsContext;
3719
- exports.FormUtils = FormUtils;
3720
- exports.HelpIcon = HelpIcon;
3721
- exports.IntlContextProvider = IntlContextProvider;
3722
- exports.JsonLdFramingUtils = JsonLdFramingUtils;
3723
- exports.JsonLdObjectMap = JsonLdObjectMap;
3724
- exports.JsonLdObjectUtils = JsonLdObjectUtils;
3725
- exports.Question = Question;
3726
- exports.QuestionStatic = QuestionStatic;
3727
- exports.WizardStep = WizardStep;
3728
- exports["default"] = SForms;
1
+ require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.array.some.js");var e=require("react"),t=require("prop-types");require("core-js/modules/es.object.assign.js");var n=require("jsonld");require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.array.find.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.array.map.js");var r=require("jsonld-utils");require("core-js/modules/es.array.sort.js"),require("core-js/modules/es.array.for-each.js"),require("core-js/modules/web.dom-collections.for-each.js");var o=require("tsort");require("core-js/modules/es.number.max-safe-integer.js"),require("core-js/modules/es.number.constructor.js");var a=require("react-dom"),s=require("react-bootstrap");require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.set.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/esnext.set.add-all.js"),require("core-js/modules/esnext.set.delete-all.js"),require("core-js/modules/esnext.set.difference.js"),require("core-js/modules/esnext.set.every.js"),require("core-js/modules/esnext.set.filter.js"),require("core-js/modules/esnext.set.find.js"),require("core-js/modules/esnext.set.intersection.js"),require("core-js/modules/esnext.set.is-disjoint-from.js"),require("core-js/modules/esnext.set.is-subset-of.js"),require("core-js/modules/esnext.set.is-superset-of.js"),require("core-js/modules/esnext.set.join.js"),require("core-js/modules/esnext.set.map.js"),require("core-js/modules/esnext.set.reduce.js"),require("core-js/modules/esnext.set.some.js"),require("core-js/modules/esnext.set.symmetric-difference.js"),require("core-js/modules/esnext.set.union.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.array.every.js"),require("core-js/modules/es.array.is-array.js"),require("core-js/modules/es.array.find-index.js"),require("core-js/modules/es.date.to-string.js");var i=require("react-datepicker"),u=require("date-fns");require("core-js/modules/es.object.get-own-property-names.js"),require("core-js/modules/es.array.index-of.js"),require("core-js/modules/es.array.slice.js");var l=require("yasgui-yasqe");require("@triply/yasgui/build/yasgui.min.css"),require("core-js/modules/web.timers.js");var c=require("inputmask-core");require("core-js/modules/es.symbol.js"),require("core-js/modules/es.symbol.description.js"),require("core-js/modules/es.function.name.js");var d=require("react-select"),f=require("react-window");require("core-js/modules/es.regexp.to-string.js"),require("core-js/modules/es.date.now.js"),require("core-js/modules/es.array.splice.js");var p=require("react/jsx-runtime");require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.string.replace.js"),require("core-js/modules/es.object.values.js"),require("core-js/modules/es.parse-int.js");var m=require("javascript-time-ago"),h=require("javascript-time-ago/locale/en"),E=require("javascript-time-ago/locale/cs"),v=require("framer-motion"),g=require("react-loader-spinner");require("core-js/modules/es.string.trim.js");var S=require("react-intl"),A=require("classnames"),_=require("react-bootstrap/Card");function C(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var T=/*#__PURE__*/C(e),N=/*#__PURE__*/C(t),O=/*#__PURE__*/C(n),I=/*#__PURE__*/C(r),y=/*#__PURE__*/C(o),w=/*#__PURE__*/C(a),b=/*#__PURE__*/C(i),L=/*#__PURE__*/C(l),R=/*#__PURE__*/C(c),x=/*#__PURE__*/C(d),q=/*#__PURE__*/C(m),H=/*#__PURE__*/C(h),D=/*#__PURE__*/C(E),U=/*#__PURE__*/C(A),V=/*#__PURE__*/C(_);function j(){return j=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},j.apply(this,arguments)}function M(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,P(e,t)}function P(e,t){return P=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},P(e,t)}function F(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}function Q(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function z(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return Q(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Q(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var k,B=/*#__PURE__*/function(){function e(){}return e.log=function(e){console.log(e)},e.warn=function(e){console.warn?console.warn(e):console.log("WARNING: "+e)},e.error=function(e){console.error?console.error(e):console.log("ERROR: "+e)},e}(),W=["children"],G=/*#__PURE__*/T.default.createContext({}),X=function(t){var n=t.children,r=F(t,W),o=[],a=function(e,t){try{var n=o[e];return n&&n.length?Promise.resolve(n):Promise.resolve(r.fetchTypeAheadValues(t)).then(function(t){return t.length?new Promise(function(n){O.default.frame(t,{},null,function(t,r){var a,s=r["@graph"];return o.push(Object.assign({},s,((a={})[e]=s,a))),n(s)})}):(B.warn("No data received when loading options using id "+e),[])})}catch(e){return Promise.reject(e)}},s=function(e){return o[e]||[]},i=e.useMemo(function(){return{loadFormOptions:a,getOptions:s}},[a,s]);/*#__PURE__*/return T.default.createElement(G.Provider,j({value:i},r),n)};X.propTypes={children:N.default.element.isRequired,fetchTypeAheadValues:N.default.func};var Y=function(){};k=Y,Y.COLUMN_COUNT=12,Y.INPUT_LENGTH_THRESHOLD=50,Y.DATETIME_NUMBER_FORMAT="x",Y.FORM="http://onto.fel.cvut.cz/ontologies/documentation/form",Y.HAS_SUBQUESTION="http://onto.fel.cvut.cz/ontologies/documentation/has_related_question",Y.HAS_ANSWER="http://onto.fel.cvut.cz/ontologies/documentation/has_answer",Y.HAS_OPTION="http://onto.fel.cvut.cz/ontologies/form/has-possible-value",Y.HAS_OPTIONS_QUERY="http://onto.fel.cvut.cz/ontologies/form/has-possible-values-query",Y.HAS_VALUE_TYPE="http://onto.fel.cvut.cz/ontologies/form/has-value-type",Y.IS_DISABLED="http://onto.fel.cvut.cz/ontologies/aviation/form-376/is-disabled",Y.INPUT_MASK="http://onto.fel.cvut.cz/ontologies/form/has-input-mask",Y.LAYOUT_CLASS="http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class",Y.LAYOUT={FORM:"form",QUESTION_SECTION:"section",WIZARD_STEP:"wizard-step",DATE:"date",TIME:"time",DATETIME:"datetime",TEXT:"text",TEXTAREA:"textarea",CHECKBOX:"checkbox",QUESTION_TYPEAHEAD:"type-ahead",MASKED_INPUT:"masked-input",ANSWERABLE:"answerable",SPARQL:"sparql",TURTLE:"ttl",DISABLED:"disabled",HIDDEN:"hidden",COLLAPSED:"collapsed",EMPHASISED:"emphasised",EMPHASISE_ON_RELEVANT:"emphasise-on-relevant",CATEGORY:["category-1","category-2","category-3","category-4","category-5"]},Y.HAS_INITIAL_INPUT_LENGTH="http://onto.fel.cvut.cz/ontologies/form-layout/has-initial-input-length",Y.VALUE_TYPE_CODE="code",Y.VALUE_TYPE_TEXT="text",Y.GENERATED_ROW_SIZE=1,Y.HAS_QUESTION_ORIGIN="http://onto.fel.cvut.cz/ontologies/form/has-question-origin",Y.HAS_ANSWER_ORIGIN="http://onto.fel.cvut.cz/ontologies/form/has-answer-origin",Y.HAS_DATA_VALUE="http://onto.fel.cvut.cz/ontologies/documentation/has_data_value",Y.HAS_OBJECT_VALUE="http://onto.fel.cvut.cz/ontologies/documentation/has_object_value",Y.HELP_DESCRIPTION="http://purl.org/dc/elements/1.1/description",Y.SOURCE="http://purl.org/dc/elements/1.1/source",Y.XSD={MAX_EXCLUSIVE:"http://www.w3.org/2001/XMLSchema#maxExclusive",MAX_INCLUSIVE:"http://www.w3.org/2001/XMLSchema#maxInclusive",MIN_EXCLUSIVE:"http://www.w3.org/2001/XMLSchema#minExclusive",MIN_INCLUSIVE:"http://www.w3.org/2001/XMLSchema#minInclusive",INT:"http://www.w3.org/2001/XMLSchema#int",INTEGER:"http://www.w3.org/2001/XMLSchema#integer",NEGATIVE_INTEGER:"http://www.w3.org/2001/XMLSchema#negativeInteger",NON_NEGATIVE_INTEGER:"http://www.w3.org/2001/XMLSchema#nonNegativeInteger",NON_POSITIVE_INTEGER:"http://www.w3.org/2001/XMLSchema#nonPositiveInteger",POSITIVE_INTEGER:"http://www.w3.org/2001/XMLSchema#positiveInteger",BOOLEAN:"http://www.w3.org/2001/XMLSchema#boolean"},Y.STEP="http://onto.fel.cvut.cz/ontologies/form/step",Y.ACCEPTS_ANSWER_VALUE="http://onto.fel.cvut.cz/ontologies/form/accepts-answer-value",Y.ACCEPTS="http://onto.fel.cvut.cz/ontologies/form/accepts",Y.HAS_DATATYPE="http://onto.fel.cvut.cz/ontologies/form/has-datatype",Y.HAS_LAYOUT_CLASS="http://onto.fel.cvut.cz/ontologies/form/has-layout-class",Y.HAS_POSSIBLE_VALUES_QUERY="http://onto.fel.cvut.cz/ontologies/form/has-possible-values-query",Y.HAS_REQUIRED_VALUE="http://onto.fel.cvut.cz/ontologies/form/has-required-value",Y.HAS_TESTED_QUESTION="http://onto.fel.cvut.cz/ontologies/form/has-tested-question",Y.HAS_TESTED_FORM="http://onto.fel.cvut.cz/ontologies/form/has-tested-form",Y.HAS_UNIT="http://onto.fel.cvut.cz/ontologies/form/has-unit",Y.HAS_VALID_ANSWER="http://onto.fel.cvut.cz/ontologies/form/has-valid-answer",Y.IS_RELEVANT_IF="http://onto.fel.cvut.cz/ontologies/form/is-relevant-if",Y.ACCEPTS_VALIDATION_VALUE="http://onto.fel.cvut.cz/ontologies/form/accepts-validation-value",Y.HAS_VALIDATION_MESSAGE="http://onto.fel.cvut.cz/ontologies/form/has-validation-message",Y.NEGATIVE_CONDITION="http://onto.fel.cvut.cz/ontologies/form/negative-condition",Y.REQUIRES_ANSWER="http://onto.fel.cvut.cz/ontologies/form/requires-answer",Y.REQUIRES_ANSWER_DESCRIPTION_IF="http://onto.fel.cvut.cz/ontologies/form/requires-answer-description-if",Y.REQUIRES_ANSWER_IF="http://onto.fel.cvut.cz/ontologies/form/requires-answer-if",Y.REQUIRES_ANSWER_VALUE="http://onto.fel.cvut.cz/ontologies/form/requires-answer-value",Y.REQUIRES_DESCRIPTION="http://onto.fel.cvut.cz/ontologies/form/requires-description",Y.HAS_PRECEDING_QUESTION="http://onto.fel.cvut.cz/ontologies/form/has-preceding-question",Y.HAS_PRECEDING_VALUE="http://onto.fel.cvut.cz/ontologies/form/has-preceding-value",Y.HAS_MEDIA_CONTENT="http://onto.fel.cvut.cz/ontologies/form/has-media-content",Y.CONDITION="http://onto.fel.cvut.cz/ontologies/form/condition",Y.OR_CONDITION="http://onto.fel.cvut.cz/ontologies/form/or-condition",Y.HAS_SUB_CONDITION="http://onto.fel.cvut.cz/ontologies/form/has-sub-condition",Y.HAS_PATTERN="http://onto.fel.cvut.cz/ontologies/form-lt/has-pattern",Y.HAS_DECLARED_PREFIX="http://onto.fel.cvut.cz/ontologies/form-spin/has-declared-prefix",Y.PREFIX="http://www.w3.org/ns/shacl#prefix",Y.NAMESPACE="http://www.w3.org/ns/shacl#namespace",Y.HAS_COMMENT="http://onto.fel.cvut.cz/ontologies/form/has-comment",Y.HAS_COMMENT_VALUE="http://onto.fel.cvut.cz/ontologies/form/has-comment-value",Y.HAS_AUTHOR="http://onto.fel.cvut.cz/ontologies/form/has-author",Y.HAS_TIMESTAMP="http://onto.fel.cvut.cz/ontologies/form/has-timestamp",Y.NOT_ANSWERED_QUESTION="http://onto.fel.cvut.cz/ontologies/form/not-answered-question",Y.ANSWERED_QUESTION="http://onto.fel.cvut.cz/ontologies/form/answered-question",Y.RDFS_LABEL=I.default.RDFS_LABEL,Y.RDFS_COMMENT=I.default.RDFS_COMMENT,Y.DEFAULT_HAS_CHILD=I.default.DEFAULT_HAS_CHILD,Y.ICONS={QUESTION_COMMENTS:"questionComments",QUESTION_HELP:"questionHelp",QUESTION_LINK:"questionLink"},Y.ICON_BEHAVIOR={ENABLE:"enable",DISABLE:"disable",ON_HOVER:"onHover"},Y.DEFAULT_OPTIONS={icons:[{id:k.ICONS.QUESTION_HELP,behavior:k.ICON_BEHAVIOR.ENABLE},{id:k.ICONS.QUESTION_COMMENTS,behavior:k.ICON_BEHAVIOR.ON_HOVER},{id:k.ICONS.QUESTION_LINK,behavior:k.ICON_BEHAVIOR.ON_HOVER}]},Y.LANG={cs:{locale:"cs",label:"Čestina"},en:{locale:"en",label:"English"}};var J=/*#__PURE__*/function(){function e(){}return e.getStringHash=function(e){var t=0,n=e?e.length:0;if(0===n)return t;for(var r=0;r<n;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return t},e.asArray=function(e){return e?e.constructor===Array?e:[e]:[]},e.findQuestionById=function(t,n,r,o,a){if(r&&n["@id"]===t)return n;var s=e.asArray(n[Y.HAS_SUBQUESTION]);if(o)for(var i,u=z(s);!(i=u()).done;){var l=e.findQuestionById(t,i.value,!0,!1,!1);if(l)return l}if(a)for(var c,d=z(s);!(c=d()).done;){var f=e.findQuestionById(t,c.value,!1,!0,!0);if(f)return f}return null},e}(),K=/*#__PURE__*/function(){function e(){}return e.putObject=function(t,n){e.objectMap[t]=n},e.getObject=function(t){return e.objectMap[t]},e}();K.objectMap={};var Z=/*#__PURE__*/function(){function e(){}return e.getFirstObject=function(e,t){var n=O.default.getValues(e,t);return 0===n.length?null:n[0]},e.compareValues=function(e,t){return t="object"==typeof t?t:{"@value":t},!!((e="object"==typeof e?e:{"@value":e})&&e["@value"]&&t&&t["@value"]&&("string"==typeof e["@value"]?e["@value"]:JSON.stringify(e["@value"]))===("string"==typeof t["@value"]?t["@value"]:JSON.stringify(t["@value"])))||O.default.compareValues(e,t)},e.toplogicalSort=function(e,t){var n;do{n=!1;for(var r=0;r<e.length;r++)for(var o=r;o<e.length;o++)if(e[r][t]&&("object"==typeof e[r][t]?e[r][t]["@id"]:e[r][t])===e[o]["@id"]){var a=e[r];e[r]=e[o],e[o]=a,n=!0;break}}while(n);return e},e.orderPreservingToplogicalSort=function(e,t){for(var n=y.default(),r={},o=function(){var o=e[a]["@id"];n.add(o),r[o]=e[a],J.asArray(e[a][t]).map(function(e){return"object"==typeof e?e["@id"]:e}).map(function(e){return[e,o]}).forEach(function(e){return n.add(e)})},a=0;a<e.length;a++)o();for(var s=n.sort(),i=0;i<s.length;i++)e[i]=r[s[i]];return e},e.getCompareLocalizedLabelFunction=function(e){return function(t,n){var r=I.default.getLocalized(t[I.default.RDFS_LABEL],e),o=I.default.getLocalized(n[I.default.RDFS_LABEL],e);return r<o?-1:r>o?1:0}},e.orderByLocalizedLabels=function(t,n){return t.sort(e.getCompareLocalizedLabelFunction(n))},e.checkId=function(e,t){if(void 0!==e)return e.constructor===Array?!!e.find(function(e){return e["@id"]===t}):e.constructor===Object?e["@id"]===t:void 0},e}(),$=/*#__PURE__*/function(){function e(){}return e.isForm=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.FORM)},e.isWizardStep=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.WIZARD_STEP)},e.isSection=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.QUESTION_SECTION)},e.isAnswerable=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.ANSWERABLE)},e.isTypeahead=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.QUESTION_TYPEAHEAD)},e.getPossibleValuesQuery=function(e){return I.default.getJsonAttValue(e,Y.HAS_OPTIONS_QUERY)},e.isDisabled=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.DISABLED)},e.isHidden=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.HIDDEN)},e.isTextarea=function(t,n){return n&&n.length>Y.INPUT_LENGTH_THRESHOLD&&!e.isTypeahead(t)||I.default.hasValue(t,Y.LAYOUT_CLASS,Y.LAYOUT.TEXTAREA)},e.isText=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.TEXT)},e.isCalendar=function(t){return e.isDate(t)||e.isTime(t)||e.isDateTime(t)},e.isDate=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.DATE)},e.isTime=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.TIME)},e.isDateTime=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.DATETIME)},e.isCheckbox=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.CHECKBOX)},e.isMaskedInput=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.MASKED_INPUT)},e.isSparqlInput=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.SPARQL)},e.isTurtleInput=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.TURTLE)},e.isCollapsed=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.COLLAPSED)},e.isEmphasised=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.EMPHASISED)},e.getCategory=function(e){return Y.LAYOUT.CATEGORY.find(function(t){return I.default.hasValue(e,Y.LAYOUT_CLASS,t)})},e.resolveValue=function(e){return e?e[Y.HAS_OBJECT_VALUE]?e[Y.HAS_OBJECT_VALUE]["@id"]:I.default.getJsonAttValue(e,Y.HAS_DATA_VALUE):null},e.resolveValueObject=function(e){return e?e[Y.HAS_OBJECT_VALUE]?J.asArray(e[Y.HAS_OBJECT_VALUE])[0]:e[Y.HAS_DATA_VALUE]?J.asArray(e[Y.HAS_DATA_VALUE])[0]:null:null},e.isRelevant=function(t){if(!t[Y.IS_RELEVANT_IF])return!0;for(var n,r=z(J.asArray(t[Y.IS_RELEVANT_IF]));!(n=r()).done;)if(!e.testCondition(n.value))return!1;return!0},e.hasValidationLogic=function(e){return!!e[Y.REQUIRES_ANSWER_VALUE]||!!e[Y.REQUIRES_ANSWER]||!!e[Y.REQUIRES_ANSWER_IF]},e.isValid=function(e){if(!1===e[Y.HAS_VALID_ANSWER])return!1;for(var t,n=z(J.asArray(e[Y.HAS_SUBQUESTION]));!(t=n()).done;)if(!1===this.isValid(t.value))return!1;return!0},e.testOrCondition=function(e){var t=e[Y.HAS_SUB_CONDITION];t||console.warn("Or condition does not have any sub-condition !");for(var n,r=z(this._getMappedObjectsArray(t));!(n=r()).done;)if(this.testCondition(n.value))return!0;return!1},e.testCondition=function(t){var n,r=t[Y.ACCEPTS_VALIDATION_VALUE],o=t[Y.ACCEPTS_ANSWER_VALUE],a=t[Y.ACCEPTS],s=t[Y.HAS_TESTED_QUESTION];if(t[Y.HAS_SUB_CONDITION])return this.testOrCondition(t);if(r&&o&&console.warn("Support for validation and requirement constraints at same time is not implemented !"),a&&s){var i=J.asArray(a);if(1!==i.length&&console.warn("Support for multiple accepts values is not implemented !"),i[0]["@id"]===Y.ANSWERED_QUESTION){(o||r)&&console.warn("Support for accepted answer/validations values is not implemented !");for(var u,l=z(this._getMappedObjectsArray(s));!(u=l()).done;)if(!this.hasAnswer(u.value))return!1;return!0}console.warn("No support to accept question of type "+i[0]["@id"]+" !")}if(r&&s){var c=J.asArray(r);(1!==c.length||!0!==c[0]&&"true"!==c[0])&&console.warn('Validation values other than "true" are not implemented !');for(var d,f=z(J.asArray(s));!(d=f()).done;){if(void 0===(n=K.getObject(d.value["@id"])))return console.warn("Questions is not loaded in an object map."),!0;if(!1===this.isValid(n))return!1}return!0}if(o&&s){n=K.getObject(s["@id"]);for(var p,m=z(J.asArray(o));!(p=m()).done;){var h=p.value;if(!n)return console.warn("Question is not defined."),!0;if(!n.hasOwnProperty(Y.HAS_ANSWER))return!1;var E=O.default.getValues(n,Y.HAS_ANSWER);if(0===E.length)return!1;var v=e.resolveValueObject(E[0]);if(v&&h&&v.hasOwnProperty("@value")&&h.hasOwnProperty("@id")&&v["@value"]==h["@id"])return!0;if(Z.compareValues(v,h))return!0}}return!1},e._getMappedObjectsArray=function(e,t){return J.asArray(e).map(function(e){var n=K.getObject(e["@id"]);return void 0===n?(console.warn((t||"Object")+' "'+e["@id"]+'" is not loaded in an object map.'),null):n}).filter(function(e){return null!==e})},e.hasAnswer=function(t){if(!t)return!1;if(t.hasOwnProperty(Y.HAS_ANSWER)){var n=O.default.getValues(t,Y.HAS_ANSWER);if(n.length){var r=e.resolveValueObject(n[0]);if(r&&(r["@value"]||r["@id"]))return!0}}for(var o,a=z(J.asArray(t[Y.HAS_SUBQUESTION]));!(o=a()).done;)if(e.hasAnswer(o.value))return!0;return!1},e.resolveDateTimeFormat=function(t,n,r){return"number"==typeof n?Y.DATETIME_NUMBER_FORMAT:e.isDate(t)?r.dateFormat:e.isTime(t)?r.timeFormat:r.dateTimeFormat},e}(),ee={},te=[],ne=/*#__PURE__*/T.default.createContext({}),re=function(t){var n=e.useState(t.data||ee),r=n[0],o=n[1],a=e.useState(t.formQuestions||te),s=a[0],i=a[1];e.useEffect(function(){if(t.isFormValid){var e=$.isValid(r);t.isFormValid(e)}},[]),e.useEffect(function(){o(t.data||ee),i(t.formQuestions||te)},[t.data,t.formQuestions]);var u=function(e){e&&o(Object.assign({},r,e))},l=function(e,n){if(!(!n||e<0||e>=s.length)){var o=[].concat(s);if(o[e]=Object.assign({},o[e],n),i(o),t.isFormValid){var a=$.isValid(r);t.isFormValid(a)}}},c=function(){return r},d=function(e){return null==e?s:s[e]},f=e.useMemo(function(){return{updateData:u,updateFormQuestionsData:l,getData:c,getFormQuestionsData:d}},[d,c]);/*#__PURE__*/return T.default.createElement(ne.Provider,j({value:f},t),t.children)};re.propTypes={children:N.default.element.isRequired,data:N.default.object.isRequired,formQuestions:N.default.array.isRequired,isFormValid:N.default.func};var oe=/*#__PURE__*/function(e){function t(t){var n;return(n=e.call(this,t)||this).state={cursorPosition:0},n}M(t,e);var n=t.prototype;return n.focus=function(){w.default.findDOMNode(this.input).focus()},n.getInputDOMNode=function(){return w.default.findDOMNode(this.input)},n.componentDidUpdate=function(e,t,n){(this.fieldDidShrink(e)||this.fieldDidExpand(e))&&this.updateFieldCursorPosition()},n.fieldDidExpand=function(e){return"textarea"===this.props.type&&"textarea"!==e.type},n.fieldDidShrink=function(e){return"text"===this.props.type&&"text"!==e.type},n.updateFieldCursorPosition=function(){this.focus(),this.getInputDOMNode().setSelectionRange(this.state.cursorPosition,this.state.cursorPosition)},n.saveCursorPosition=function(e){this.props.onChange(e),this.setState({cursorPosition:e.target.selectionStart})},n.render=function(){switch(this.props.type){case"radio":return this._renderRadio();case"checkbox":return this._renderCheckbox();case"select":return this._renderSelect();case"textarea":return this._renderTextArea();default:return this._renderInput()}},n._renderCheckbox=function(){var e=this;/*#__PURE__*/return T.default.createElement(s.Form.Group,{size:"small",controlId:Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)},/*#__PURE__*/T.default.createElement(s.Form.Check,j({type:"checkbox",ref:function(t){return e.input=t}},this.props,{label:this.props.label})))},n._renderRadio=function(){var e=this;/*#__PURE__*/return T.default.createElement(s.FormGroup,{size:"small"},/*#__PURE__*/T.default.createElement(s.Form.Check,j({type:"radio",ref:function(t){return e.input=t}},this.props,{label:this.props.label})))},n._renderSelect=function(){var e=this;/*#__PURE__*/return T.default.createElement(s.FormGroup,{size:"small"},this._renderLabel(),/*#__PURE__*/T.default.createElement(s.FormControl,j({as:"select",ref:function(t){return e.input=t}},this.props),this.props.children),this.props.validation&&/*#__PURE__*/T.default.createElement(s.FormControl.Feedback,null),this._renderHelp())},n._renderLabel=function(){return this.props.label?/*#__PURE__*/T.default.createElement(s.Form.Label,null,this.props.label):null},n._renderTextArea=function(){var e=this;/*#__PURE__*/return T.default.createElement(s.FormGroup,{size:"small"},this._renderLabel(),/*#__PURE__*/T.default.createElement(s.FormControl,j({ref:function(t){return e.input=t},as:"textarea"},this.props,{onChange:function(t){return e.saveCursorPosition(t)}})),this.props.validation&&/*#__PURE__*/T.default.createElement(s.FormControl.Feedback,null),this._renderHelp())},n._renderHelp=function(){return this.props.help?/*#__PURE__*/T.default.createElement(s.FormText,null,this.props.help):null},n._renderInput=function(){var e=this;/*#__PURE__*/return T.default.createElement(s.FormGroup,{size:"small"},this._renderLabel(),/*#__PURE__*/T.default.createElement(s.FormControl,j({ref:function(t){return e.input=t},as:"input"},this.props,{onChange:function(t){return e.saveCursorPosition(t)}})),this.props.validation&&/*#__PURE__*/T.default.createElement(s.FormControl.Feedback,null),this._renderHelp())},t}(T.default.Component);oe.propTypes={type:N.default.string,label:N.default.object,value:N.default.any,onChange:N.default.func,help:N.default.string,validation:N.default.oneOf(["success","warning","error"])},oe.defaultProps={type:"text"};var ae=["children"],se=/*#__PURE__*/T.default.createContext({}),ie={components:{inputComponent:oe},componentsOptions:{dateTimeAnswer:{dateFormat:"yyyy-MM-dd",timeFormat:"HH:mm:ss",dateTimeFormat:"yyyy-MM-dd HH:mm:ss"},readOnly:!1},options:{intl:{locale:"en"},i18n:{"wizard.next":"Next","wizard.previous":"Previous","section.collapse":"Collapse","section.expand":"Expand"},modalView:!1,modalProps:{},horizontalWizardNav:!0,wizardStepButtons:!0,enableForwardSkip:!1,startingStep:0}},ue=function(t){var n=t.children,r=F(t,ae),o=e.useMemo(function(){return{inputComponent:r.components&&r.components.inputComponent||ie.components.inputComponent,componentsOptions:Object.assign({},ie.componentsOptions,r.componentsOptions),options:Object.assign({},ie.options,r.options),mapComponent:r.mapComponent}},[r]);/*#__PURE__*/return T.default.createElement(se.Provider,{value:o},n)};ue.propTypes={children:N.default.element.isRequired,components:N.default.object,mapComponent:N.default.func,options:N.default.object};var le,ce,de={"@graph":[{"@type":"http://onto.fel.cvut.cz/ontologies/documentation/question","http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class":"form","http://onto.fel.cvut.cz/ontologies/documentation/has_related_question":[{"http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class":["wizard-step","section"],"http://www.w3.org/2000/01/rdf-schema#label":[{"@language":"en","@value":"Description"},{"@language":"cs","@value":"Popis"}],"http://onto.fel.cvut.cz/ontologies/documentation/has_related_question":[{"@type":"http://onto.fel.cvut.cz/ontologies/documentation/question","http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class":["textarea"],"http://www.w3.org/2000/01/rdf-schema#label":[{"@language":"en","@value":"Description"},{"@language":"cs","@value":"Popis"}],"http://onto.fel.cvut.cz/ontologies/documentation/has_answer":{"@type":"http://onto.fel.cvut.cz/ontologies/documentation/answer","http://onto.fel.cvut.cz/ontologies/documentation/has_data_value":""}}]}]}]},fe=/*#__PURE__*/function(){function e(){}return e.generateForm=function(){return JSON.parse(JSON.stringify(de))},e}(),pe={root:(le={},le[Y.HAS_LAYOUT_CLASS]=Y.FORM,le),expandProperties:[Y.HAS_SUBQUESTION,Y.IS_RELEVANT_IF,Y.HAS_ANSWER,Y.HAS_DECLARED_PREFIX,Y.HAS_OPTION,Y.HAS_COMMENT]},me=/*#__PURE__*/function(){function e(){}return e.customFrame=function(e,t,n){if(arguments.length<2)return O.default.nextTick(function(){n(new TypeError("Could not frame, too few arguments."))});null===t&&(t=pe),O.default.flatten(e,null,null,function(e,t){})},e.expandStructure=function(e){var t,n={};e["@graph"].forEach(function(e){n[e["@id"]]=e,$.isForm(e)&&(t=e)});try{this._expandGraph(t,pe,n)}catch(e){console.error("Error '"+e+"' occured, while trying to apply frame-ing with custom shape.")}return n},e._expandGraph=function(e,t,n){var r,o,a,s=this;t.expandProperties.forEach(function(i){if(e.hasOwnProperty(i)){e[i]=J.asArray(e[i]),r=e[i];for(var u=0;u<r.length;u++)a=s._getId(r[u]),void 0!==(o=n[a])?(r[u]=o,s._expandGraph(o,t,n)):console.warn("object with @id "+a+" was not defined in input data.")}})},e._getId=function(e){return"string"==typeof e?e:e["@id"]},e}();ce=me,me.compressStructure=function(e){var t=[],n=new Set;return(t=ce._compressGraph(e,t,n)).sort(function(e,t){return e["@id"]&&t["@id"]?e["@id"].localeCompare(t["@id"]):0})},me._compressGraph=function(e,t,n){return n.has(e["@id"])||(t.push(e),n.add(e["@id"])),pe.expandProperties.forEach(function(r){if(e.hasOwnProperty(r))for(var o=e[r],a=0;a<o.length;a++){var s=o[a];void 0!==s&&(o[a]=s,t=ce._compressGraph(s,t,n),e[r][a]={"@id":s["@id"]})}}),t};var he=/*#__PURE__*/function(){function e(){}return e.constructDefaultForm=function(t){var n=fe.generateForm();return e._constructFormQuestions(n,t)},e.constructForm=function(t,n){return new Promise(function(r){return O.default.flatten(t,{},null,function(t,o){var a,s;t&&B.error(t);try{var i=e._constructFormQuestions(o,n);s=i[1],a={formQuestions:i[0]}}catch(t){var u=e.constructDefaultForm(n);s=u[1],a={formQuestions:u[0]}}return r([a,s])})})},e._constructFormQuestions=function(e,t){var n,r,o,a=[];if(void 0!==e["@graph"][0]["@id"]?(o=me.expandStructure(e),Object.keys(o).map(function(e){K.putObject(e,o[e])})):console.warn("default form is constructed."),!(r=(n=e["@graph"].find(function(e){return $.isForm(e)}))[Y.HAS_SUBQUESTION]))throw B.error("Could not find any questions in the received data."),"No questions in the form";return(a=r.filter(function(e){return!(!$.isWizardStep(e)||$.isHidden(e))||(B.warn("Item is not a wizard step: "+e),!1)})).length||(B.log("Could not find any wizard steps in the received data. Building form without steps"),n[Y.HAS_SUBQUESTION].forEach(function(e){return a.push(e)})),a.sort(Z.getCompareLocalizedLabelFunction(t)),Z.orderPreservingToplogicalSort(a,Y.HAS_PRECEDING_QUESTION),[a,{root:n}]},e}(),Ee=/*#__PURE__*/function(){function e(){}return e.buildQuestionAnswerModel=function(t,n){var r,o={subQuestions:[]};if(t&&(o.uri=t.root["@id"],o.origin=I.default.getJsonAttValue(t.root,Y.HAS_QUESTION_ORIGIN,"@id")),n)for(var a=0;a<n.length;a++)(r=e.processQuestionAnswerHierarchy(n[a]))&&o.subQuestions.push(r);return o},e.processQuestionAnswerHierarchy=function(t){return t?e._processQuestion(t):null},e._processQuestion=function(t){var n={};if(n.uri=t["@id"],n.origin=I.default.getJsonAttValue(t,Y.HAS_QUESTION_ORIGIN,"@id"),t[Y.HAS_SUBQUESTION]){n.subQuestions=[];for(var r=0;r<t[Y.HAS_SUBQUESTION].length;r++)n.subQuestions.push(e._processQuestion(t[Y.HAS_SUBQUESTION][r]))}if(t[Y.HAS_ANSWER]){n.answers=[],Array.isArray(t[Y.HAS_ANSWER])||(t[Y.HAS_ANSWER]=[t[Y.HAS_ANSWER]]);for(var o=0;o<t[Y.HAS_ANSWER].length;o++)n.answers.push(e.processAnswer(t[Y.HAS_ANSWER][o]))}if(t[Y.HAS_COMMENT]){n.comments=[],Array.isArray(t[Y.HAS_COMMENT])||(t[Y.HAS_COMMENT]=[t[Y.HAS_COMMENT]]);for(var a=0;a<t[Y.HAS_COMMENT].length;a++)n.comments.push(e.processComment(t[Y.HAS_COMMENT][a]))}return n},e.processComment=function(e){var t={};return t.author=I.default.getJsonAttValue(e,Y.HAS_AUTHOR,"@id"),t.value=I.default.getJsonAttValue(e,Y.HAS_COMMENT_VALUE),t.timestamp=I.default.getJsonAttValue(e,Y.HAS_TIMESTAMP,"@id"),t},e.processAnswer=function(e){var t={};return t.uri=e["@id"],t.origin=I.default.getJsonAttValue(e,Y.HAS_ANSWER_ORIGIN,"@id"),e[Y.HAS_OBJECT_VALUE]?t.codeValue=I.default.getJsonAttValue(e,Y.HAS_OBJECT_VALUE,"@id"):t.textValue=I.default.getJsonAttValue(e,Y.HAS_DATA_VALUE),t},e.generateAnswer=function(e){var t={};return t[Y.HAS_DATA_VALUE]="",t},e}(),ve=/*#__PURE__*/function(){function e(){}return e.resolveValidationProperties=function(e){var t={};return!1===e[Y.HAS_VALID_ANSWER]&&(t.validation="error",t.help=e[Y.HAS_VALIDATION_MESSAGE]),t},e}(),ge=function(t){var n=e.useContext(se),r=n.componentsOptions,o=t.question;/*#__PURE__*/return T.default.createElement(n.inputComponent,Object.assign({},ve.resolveValidationProperties(o),{type:"checkbox",label:t.label,title:t.title,checked:!0===t.value||"true"===t.value,onChange:function(e){t.onChange(e.target.checked)},disabled:r.readOnly||$.isDisabled(o)}))};ge.propTypes={question:N.default.object.isRequired,label:N.default.object.isRequired,title:N.default.string,value:N.default.oneOfType([N.default.string,N.default.bool]),onChange:N.default.func.isRequired,mouseHover:N.default.bool};var Se=function(t){var n,r=e.useContext(se).componentsOptions,o=$.resolveDateTimeFormat(t.question,t.value,r.dateTimeAnswer),a=$.isDate(t.question),i=$.isTime(t.question);n=i&&t.value?new Date("0 "+t.value):t.value?new Date(t.value):null;var l="x"===o?r.dateTimeAnswer.dateTimeFormat:o;/*#__PURE__*/return T.default.createElement(s.FormGroup,{size:"small"},/*#__PURE__*/T.default.createElement(s.Form.Label,{className:"w-100"},t.label),/*#__PURE__*/T.default.createElement(b.default,{selected:n,placeholderText:l.toUpperCase(),onChange:function(e){t.onChange(o===Y.DATETIME_NUMBER_FORMAT?Number(e):u.format(e,o))},showTimeSelect:!a,showTimeSelectOnly:i,timeFormat:"HH:mm",timeIntervals:1,timeCaption:"Time",dateFormat:l,className:"form-control",disabled:r.readOnly||$.isDisabled(t.question)}))};Se.propTypes={question:N.default.object.isRequired,label:N.default.object.isRequired,title:N.default.string,value:N.default.oneOfType([N.default.string,N.default.number]),onChange:N.default.func.isRequired};var Ae=[Y.XSD.INT,Y.XSD.INTEGER,Y.XSD.NON_NEGATIVE_INTEGER,Y.XSD.NON_POSITIVE_INTEGER,Y.XSD.NEGATIVE_INTEGER,Y.XSD.POSITIVE_INTEGER],_e={};_e[Y.XSD.NON_NEGATIVE_INTEGER]={min:0},_e[Y.XSD.NON_POSITIVE_INTEGER]={max:0},_e[Y.XSD.NEGATIVE_INTEGER]={max:-1},_e[Y.XSD.POSITIVE_INTEGER]={min:1};var Ce={"string-2":"prefixed",atom:"var"},Te=/*#__PURE__*/function(){function e(){}return e._resolveInputType=function(t,n){return $.isSparqlInput(t)||$.isTurtleInput(t)||$.isTextarea(t,n)?"textarea":e._isNumeric(t)?"number":"text"},e._isNumeric=function(e){for(var t=0,n=Ae.length;t<n;t++)if(I.default.hasValue(e,Y.HAS_DATATYPE,Ae[t]))return!0;return!1},e.resolveInputProperties=function(t,n,r){var o={};switch(o.type=e._resolveInputType(t,n),o.type){case"textarea":o.rows=5;break;case"number":o=Object.assign({},o,e._resolveNumberRestrictions(t),this._resolveStepRestriction(t))}return o.disabled=r.readOnly||$.isDisabled(t),!1===t[Y.HAS_VALID_ANSWER]&&(o.validation="error",o.help=t[Y.HAS_VALIDATION_MESSAGE]),o},e._resolveStepRestriction=function(e){var t={};return void 0!==e[Y.STEP]&&(t.step=I.default.getJsonAttValue(e,Y.STEP)),t},e._resolveNumberRestrictions=function(e){var t={};return Object.getOwnPropertyNames(_e).forEach(function(n){I.default.hasValue(e,Y.HAS_DATATYPE,n)&&(t=Object.assign({},t,_e[n]))}),void 0!==e[Y.XSD.MIN_INCLUSIVE]&&(t.min=e[Y.XSD.MIN_INCLUSIVE]),void 0!==e[Y.XSD.MIN_EXCLUSIVE]&&(t.min=e[Y.XSD.MIN_EXCLUSIVE]+1),void 0!==e[Y.XSD.MAX_EXCLUSIVE]&&(t.max=e[Y.XSD.MAX_EXCLUSIVE]-1),void 0!==e[Y.XSD.MAX_INCLUSIVE]&&(t.max=e[Y.XSD.MAX_INCLUSIVE]),t},e}(),Ne=function(t){var n=e.useContext(se),r=n.inputComponent,o=n.componentsOptions,a=t.question,s=t.answer,i=t.value;return s[Y.HAS_OBJECT_VALUE]&&s[Y.HAS_OBJECT_VALUE][I.default.RDFS_LABEL]&&(i=I.default.getJsonAttValue(s[Y.HAS_OBJECT_VALUE],I.default.RDFS_LABEL)),/*#__PURE__*/T.default.createElement(r,Object.assign({},Te.resolveInputProperties(a,i,o),{label:t.label,title:t.title,value:null==i?"":i,onChange:function(e){t.onChange(e.target.value),(t.sparql||t.turtle)&&(void 0).hide()},onFocus:function(e){if(t.sparql){var n=L.default.fromTextArea(e.target);n.setValue(i),n.on("change",function(){t.onChange(n.getValue())}),L.default.Autocompleters.prefixes.appendPrefixIfNeeded=function(e,n){if(e.autocompleters.getTrie(n)&&e.options.autocompleters&&-1!==e.options.autocompleters.indexOf(n)){var r=e.getCursor(),o=e.getTokenAt(r);if("prefixed"===Ce[o.type]){var a=o.string.indexOf(":");if(-1!==a){var s=e.getPreviousNonWsToken(r.line,o).string.toUpperCase(),i=e.getTokenAt({line:r.line,ch:o.start});if("PREFIX"!==s&&("ws"===i.type||null==i.type)){var u=o.string.substring(0,a+1);if(null==e.getPrefixesFromQuery()[u.slice(0,-1)])if(t.question[Y.HAS_DECLARED_PREFIX]&&t.question[Y.HAS_DECLARED_PREFIX].filter(function(e){return e[Y.PREFIX]===u.slice(0,-1)}).length){var l=t.question[Y.HAS_DECLARED_PREFIX].filter(function(e){return e[Y.PREFIX]===u.slice(0,-1)}),c={};c[l[0][Y.PREFIX]]=l[0][Y.NAMESPACE],e.addPrefixes(c)}else{var d=e.autocompleters.getTrie(n).autoComplete(u);d.length>0&&e.addPrefixes(d[0])}}}}}}}else if(t.turtle){console.log("TTL");var r=L.default.fromTextArea(e.target);r.setValue(i),r.on("change",function(){t.onChange(r.getValue())})}}}))};Ne.propTypes={question:N.default.object.isRequired,answer:N.default.object.isRequired,label:N.default.object.isRequired,title:N.default.string,value:N.default.oneOfType([N.default.string,N.default.number]),onChange:N.default.func.isRequired};var Oe={D:"1",M:"1",Y:"1",h:"1",m:"1",s:"1"},Ie=/*#__PURE__*/function(){function e(){}return e.mapMask=function(e){if(!e)return e;for(var t,n="",r=0,o=e.length;r<o;r++)t=e.charAt(r),n+=Oe[t]?Oe[t]:t;return n},e}(),ye=["size","placeholder"];function we(e){var t,n,r,o;if(void 0!==e.selectionStart)t=e.selectionStart,n=e.selectionEnd;else try{e.focus(),o=(r=e.createTextRange()).duplicate(),r.moveToBookmark(document.selection.createRange().getBookmark()),o.setEndPoint("EndToStart",r),n=(t=o.text.length)+r.text.length}catch(e){}return{start:t,end:n}}var be=/*#__PURE__*/function(e){function t(t){var n;return(n=e.call(this,t)||this)._updatePattern=function(e){n.mask.setPattern(Ie.mapMask(e.mask),{value:n.mask.getRawValue(),selection:we(n.input)})},n._updateMaskSelection=function(){n.mask.selection=we(n.input)},n._updateInputSelection=function(){!function(e,t){var n;try{void 0!==e.selectionStart?(e.focus(),e.setSelectionRange(t.start,t.end)):(e.focus(),(n=e.createTextRange()).collapse(!0),n.moveStart("character",t.start),n.moveEnd("character",t.end-t.start),n.select())}catch(e){}}(n.input,n.mask.selection)},n._onChange=function(e){var t=n.mask.getValue();if(e.target.value!==t){if(e.target.value.length<t.length){var r=t.length-e.target.value.length;n._updateMaskSelection(),n.mask.selection.end=n.mask.selection.start+r,n.mask.backspace()}var o=n._getDisplayValue();e.target.value=o,o&&n._updateInputSelection()}n.props.onChange&&n.props.onChange(e)},n._onKeyDown=function(e){if(function(e){return e.ctrlKey&&90===e.keyCode}(e))e.preventDefault(),n.mask.undo()&&(e.target.value=n._getDisplayValue(),n._updateInputSelection(),n.props.onChange&&n.props.onChange(e));else if(function(e){return e.ctrlKey&&89===e.keyCode}(e))e.preventDefault(),n.mask.redo()&&(e.target.value=n._getDisplayValue(),n._updateInputSelection(),n.props.onChange&&n.props.onChange(e));else if("Backspace"===e.key&&(e.preventDefault(),n._updateMaskSelection(),n.mask.backspace())){var t=n._getDisplayValue();e.target.value=t,t&&n._updateInputSelection(),n.props.onChange&&n.props.onChange(e)}},n._onKeyPress=function(e){e.metaKey||e.altKey||e.ctrlKey||"Enter"===e.key||(e.preventDefault(),n._updateMaskSelection(),n.mask.input(e.key)&&(e.target.value=n.mask.getValue(),n._updateInputSelection(),n.props.onChange&&n.props.onChange(e)))},n._onPaste=function(e){e.preventDefault(),n._updateMaskSelection(),n.mask.paste(e.clipboardData.getData("Text"))&&(e.target.value=n.mask.getValue(),setTimeout(n._updateInputSelection,0),n.props.onChange&&n.props.onChange(e))},n.mask=new R.default({pattern:Ie.mapMask(t.mask),value:t.value,formatCharacters:t.formatCharacters,placeholderChar:t.placeholderChar||"_"}),n}M(t,e);var n=t.prototype;return n.componentDidUpdate=function(e){e.mask!==this.props.mask&&this._updatePattern(this.props),e.mask!==this.props.mask&&e.value!==this.props.mask?this.mask.getValue()===this.mask.emptyValue?this.mask.setPattern(Ie.mapMask(this.props.mask),{value:this.props.value}):this.mask.setPattern(Ie.mapMask(this.props.mask),{value:this.mask.getRawValue()}):e.mask!==this.props.mask?this.mask.setPattern(Ie.mapMask(this.props.mask),{value:this.mask.getRawValue()}):e.value!==this.props.value&&this.mask.setValue(this.props.value),e.mask!==this.props.mask&&this.mask.selection.start&&this._updateInputSelection()},n._getDisplayValue=function(){var e=this.mask.getValue();return e===this.mask.emptyValue?"":e},n.focus=function(){this.input.focus()},n.blur=function(){this.input.blur()},n.render=function(){var e=this,t=this.props,n=t.size,r=t.placeholder,o=F(t,ye),a=this.mask.pattern.length;/*#__PURE__*/return T.default.createElement(this.context.inputComponent,Object.assign({},o,{ref:function(t){t&&(e.input=t.input?w.default.findDOMNode(t.input):t)},maxLength:a,onChange:this._onChange,onKeyDown:this._onKeyDown,onKeyPress:this._onKeyPress,onPaste:this._onPaste,placeholder:r||this.mask.emptyValue,size:n||a,value:this._getDisplayValue(),type:"text"}))},t}(T.default.Component);be.contextType=se,be.propTypes={mask:N.default.string.isRequired},be.defaultProps={value:""};var Le=function(t){var n=e.useContext(se).componentsOptions,r=t.question,o=t.value,a=I.default.getJsonAttValue(r,Y.INPUT_MASK);return a?/*#__PURE__*/T.default.createElement(be,{mask:a,value:o,label:t.label,title:t.title,placeholder:a,onChange:function(e){return t.onChange(e.target.value)},disabled:n.readOnly||$.isDisabled(r)}):(B.warn("Input mask not provided. Falling back to regular input."),/*#__PURE__*/T.default.createElement(Ne,t))};Le.propTypes={question:N.default.object.isRequired,answer:N.default.object.isRequired,label:N.default.object.isRequired,title:N.default.string,value:N.default.oneOfType([N.default.string,N.default.number]),onChange:N.default.func.isRequired};var Re=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}M(t,e);var n=t.prototype;return n._generateSelectOptions=function(e){var t=[];e.sort(function(e,t){var n=I.default.getJsonAttValue(e,Y.RDFS_LABEL),r=I.default.getJsonAttValue(t,Y.RDFS_LABEL);return n<r?-1:n>r?1:0});for(var n=0;n<e.length;n++)t.push(/*#__PURE__*/T.default.createElement("option",{value:I.default.getJsonAttValue(e[n],Y.RDFS_LABEL),key:"opt-"+n},I.default.getJsonAttValue(e[n],Y.RDFS_LABEL)));return t},n.render=function(){var e=this,t=this.props.question;/*#__PURE__*/return T.default.createElement(this.context.inputComponent,{type:"select",label:this.props.label,value:this.props.value,title:this.props.title,onChange:function(t){e.props.onChange(t.target.value)},disabled:this.context.componentsOptions.readOnly||$.isDisabled(t)},this._generateSelectOptions(t[Y.HAS_OPTION]))},t}(T.default.Component);Re.contextType=se,Re.propTypes={question:N.default.object.isRequired,label:N.default.object.isRequired,title:N.default.string,value:N.default.string,onChange:N.default.func.isRequired};var xe=function(e){var t=e.options,n=e.children,r=e.maxHeight,o=(0,e.getValue)(),a=o&&o[0]?40*t.indexOf(o[0]):0;/*#__PURE__*/return T.default.createElement(f.FixedSizeList,{height:r,itemCount:n.length,itemSize:40,initialScrollOffset:a,width:""},function(e){/*#__PURE__*/return T.default.createElement("div",{className:"option-wrapper",style:e.style},n[e.index])})},qe=function(e,t){return e?(e.sort(Z.getCompareLocalizedLabelFunction(t)),Z.orderPreservingToplogicalSort(e,Y.HAS_PRECEDING_VALUE),I.default.processTypeaheadOptions(e,t)):[]},He=function(t){var n=J.getStringHash($.getPossibleValuesQuery(t.question)),r=e.useContext(G),o=e.useContext(se),a=o.options.intl,i=e.useState(!0),u=i[0],l=i[1],c=e.useState(qe(t.options,a)),f=c[0],p=c[1];e.useEffect(function(){var e=!1,o=t.question;return!o[Y.HAS_OPTION]&&$.getPossibleValuesQuery(o)?function(){try{var t=function(t,s){try{var i=Promise.resolve(r.loadFormOptions(n,$.getPossibleValuesQuery(o))).then(function(t){e||(l(!1),p(qe(t,a)))})}catch(e){return s()}return i&&i.then?i.then(void 0,s):i}(0,function(){B.error("An error has occurred during loadFormOptions for query hash: "+n)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}():(l(!1),p(qe(o[Y.HAS_OPTION],a))),function(){e=!0}},[]),e.useEffect(function(){p(qe(t.question[Y.HAS_OPTION],a))},[a]);var m=d.components.Option;/*#__PURE__*/return T.default.createElement(s.FormGroup,{size:"small"},/*#__PURE__*/T.default.createElement(s.Form.Label,null,t.label),/*#__PURE__*/T.default.createElement(x.default,{options:f,isSearchable:!0,isLoading:u,isClearable:!0,isDisabled:u||o.componentsOptions.readOnly||$.isDisabled(t.question),value:f.filter(function(e){return e.id===t.value}),placeholder:"",getOptionLabel:function(e){return e.name},getOptionValue:function(e){return e.id},onChange:function(e){t.onChange(e?e.id:null)},components:{MenuList:xe,Option:function(e){var t=Object.assign({},e.innerProps,{title:e.data.description});/*#__PURE__*/return T.default.createElement(m,j({},e,{title:e.data.description,innerProps:t}))}}}))};He.propTypes={question:N.default.object.isRequired,answer:N.default.object.isRequired,label:N.default.oneOfType([N.default.string,N.default.object]).isRequired,title:N.default.string,value:N.default.string,onChange:N.default.func.isRequired};var De=function(e){/*#__PURE__*/return T.default.createElement("svg",{className:"caret-square-up",version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"28",viewBox:"0 0 24 28"},/*#__PURE__*/T.default.createElement("title",null,e.title||""),/*#__PURE__*/T.default.createElement("path",{d:"M17.891 17.453c-0.172 0.344-0.516 0.547-0.891 0.547h-10c-0.375 0-0.719-0.203-0.891-0.547-0.172-0.328-0.141-0.734 0.078-1.031l5-7c0.187-0.266 0.484-0.422 0.812-0.422s0.625 0.156 0.812 0.422l5 7c0.219 0.297 0.25 0.703 0.078 1.031zM20 21.5v-15c0-0.266-0.234-0.5-0.5-0.5h-15c-0.266 0-0.5 0.234-0.5 0.5v15c0 0.266 0.234 0.5 0.5 0.5h15c0.266 0 0.5-0.234 0.5-0.5zM24 6.5v15c0 2.484-2.016 4.5-4.5 4.5h-15c-2.484 0-4.5-2.016-4.5-4.5v-15c0-2.484 2.016-4.5 4.5-4.5h15c2.484 0 4.5 2.016 4.5 4.5z"}))},Ue=function(e){/*#__PURE__*/return T.default.createElement("svg",{className:"caret-square-down",version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"28",viewBox:"0 0 24 28"},/*#__PURE__*/T.default.createElement("title",null,e.title||""),/*#__PURE__*/T.default.createElement("path",{d:"M17.891 10.547c0.172 0.328 0.141 0.734-0.078 1.031l-5 7c-0.187 0.266-0.484 0.422-0.812 0.422s-0.625-0.156-0.812-0.422l-5-7c-0.219-0.297-0.25-0.703-0.078-1.031 0.172-0.344 0.516-0.547 0.891-0.547h10c0.375 0 0.719 0.203 0.891 0.547zM20 21.5v-15c0-0.266-0.234-0.5-0.5-0.5h-15c-0.266 0-0.5 0.234-0.5 0.5v15c0 0.266 0.234 0.5 0.5 0.5h15c0.266 0 0.5-0.234 0.5-0.5zM24 6.5v15c0 2.484-2.016 4.5-4.5 4.5h-15c-2.484 0-4.5-2.016-4.5-4.5v-15c0-2.484 2.016-4.5 4.5-4.5h15c2.484 0 4.5 2.016 4.5 4.5z"}))},Ve=function(){/*#__PURE__*/return T.default.createElement("svg",{className:"info-circle",version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"28",viewBox:"0 0 24 28"},/*#__PURE__*/T.default.createElement("title",null,"info-circle"),/*#__PURE__*/T.default.createElement("path",{d:"M16 21.5v-2.5c0-0.281-0.219-0.5-0.5-0.5h-1.5v-8c0-0.281-0.219-0.5-0.5-0.5h-5c-0.281 0-0.5 0.219-0.5 0.5v2.5c0 0.281 0.219 0.5 0.5 0.5h1.5v5h-1.5c-0.281 0-0.5 0.219-0.5 0.5v2.5c0 0.281 0.219 0.5 0.5 0.5h7c0.281 0 0.5-0.219 0.5-0.5zM14 7.5v-2.5c0-0.281-0.219-0.5-0.5-0.5h-3c-0.281 0-0.5 0.219-0.5 0.5v2.5c0 0.281 0.219 0.5 0.5 0.5h3c0.281 0 0.5-0.219 0.5-0.5zM24 14c0 6.625-5.375 12-12 12s-12-5.375-12-12 5.375-12 12-12 12 5.375 12 12z"}))},je=function(){/*#__PURE__*/return T.default.createElement("svg",{className:"question-circle",version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"24",height:"28",viewBox:"0 0 24 28"},/*#__PURE__*/T.default.createElement("path",{d:"M14 21.5v-3c0-0.281-0.219-0.5-0.5-0.5h-3c-0.281 0-0.5 0.219-0.5 0.5v3c0 0.281 0.219 0.5 0.5 0.5h3c0.281 0 0.5-0.219 0.5-0.5zM18 11c0-2.859-3-5-5.688-5-2.547 0-4.453 1.094-5.797 3.328-0.141 0.219-0.078 0.5 0.125 0.656l2.063 1.563c0.078 0.063 0.187 0.094 0.297 0.094 0.141 0 0.297-0.063 0.391-0.187 0.734-0.938 1.047-1.219 1.344-1.437 0.266-0.187 0.781-0.375 1.344-0.375 1 0 1.922 0.641 1.922 1.328 0 0.812-0.422 1.219-1.375 1.656-1.109 0.5-2.625 1.797-2.625 3.313v0.562c0 0.281 0.219 0.5 0.5 0.5h3c0.281 0 0.5-0.219 0.5-0.5v0c0-0.359 0.453-1.125 1.188-1.547 1.188-0.672 2.812-1.578 2.812-3.953zM24 14c0 6.625-5.375 12-12 12s-12-5.375-12-12 5.375-12 12-12 12 5.375 12 12z"}))},Me=function(t){var n=e.useState("right"),r=n[0],o=n[1];/*#__PURE__*/return T.default.createElement("span",{ref:function(e){return function(e){e&&(e.getBoundingClientRect().x>window.innerWidth/2?o("left"):o("right"))}(e)}},/*#__PURE__*/T.default.createElement(s.OverlayTrigger,{overlay:/*#__PURE__*/T.default.createElement(s.Tooltip,{className:"tooltip-content",id:t.id},t.tooltipContent),placement:t.overlayPlacement||r},/*#__PURE__*/T.default.createElement("span",null,t.children)))};Me.propTypes={tooltipContent:N.default.oneOfType([N.default.object.isRequired,N.default.string.isRequired]),id:N.default.string.isRequired,overlayPlacement:N.default.string,absolutePosition:N.default.bool},Me.defaultProps={iconClassContainer:"",iconClass:"",absolutePosition:!0};var Pe=function(t){var n=e.useState("right"),r=n[1];/*#__PURE__*/return T.default.createElement("div",{ref:function(e){return function(e){e&&(e.getBoundingClientRect().x>window.innerWidth/2?r("left"):r("right"))}(e)}},/*#__PURE__*/T.default.createElement(Me,{id:"help-icon-tooltip-",overlayPlacement:t.overlayPlacement||n[0],absolutePosition:t.absolutePosition,tooltipContent:t.text},/*#__PURE__*/T.default.createElement(je,{className:t.iconClass})))};Pe.propTypes={text:N.default.string.isRequired,iconClassContainer:N.default.string,iconClass:N.default.string,overlayPlacement:N.default.string,absolutePosition:N.default.bool},Pe.defaultProps={iconClassContainer:"",iconClass:"",absolutePosition:!0};var Fe=function(){/*#__PURE__*/return T.default.createElement("svg",{className:"external-link-icon",width:"24",height:"16",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},/*#__PURE__*/T.default.createElement("path",{d:"M5,2 C5.55228,2 6,2.44772 6,3 C6,3.55228 5.55228,4 5,4 L4,4 L4,12 L12,12 L12,11 C12,10.4477 12.4477,10 13,10 C13.5523,10 14,10.4477 14,11 L14,12 C14,13.1046 13.1046,14 12,14 L4,14 C2.89543,14 2,13.1046 2,12 L2,4 C2,2.89543 2.89543,2 4,2 L5,2 Z M15,1 L15,5.99814453 C15,6.55043453 14.5523,6.99814453 14,6.99814453 C13.4477,6.99814453 13,6.55043453 13,5.99814453 L13,4.41419 L8.71571,8.69846 C8.32519,9.08899 7.69202,9.08899 7.3015,8.69846 C6.91097,8.30794 6.91097,7.67477 7.3015,7.28425 L11.5858,3 L9.99619141,3 C9.44391141,3 8.99619141,2.55228 8.99619141,2 C8.99619141,1.44772 9.44391141,1 9.99619141,1 L15,1 Z"}))},Qe=function(e){/*#__PURE__*/return T.default.createElement(Me,{tooltipContent:e.url["@id"]||e.url,id:"url-tooltip",overlayPlacement:e.overlayPlacement},/*#__PURE__*/T.default.createElement("a",{href:e.url["@id"]||e.url,target:"_blank",className:e.iconClassContainer},/*#__PURE__*/T.default.createElement(Fe,{className:e.iconClass})))};Qe.propTypes={url:N.default.oneOfType([N.default.string.isRequired,N.default.object.isRequired]),iconClassContainer:N.default.string,iconClass:N.default.string,overlayPlacement:N.default.string,absolutePosition:N.default.bool},Qe.defaultProps={iconClassContainer:"",iconClass:"",absolutePosition:!0};var ze=function(){/*#__PURE__*/return T.default.createElement("svg",{className:"question-comment",version:"1.1",id:"Capa_1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 60 60",width:"24",height:"28"},/*#__PURE__*/T.default.createElement("path",{d:"M30,1.5c-16.542,0-30,12.112-30,27c0,5.204,1.646,10.245,4.768,14.604c-0.591,6.537-2.175,11.39-4.475,13.689 c-0.304,0.304-0.38,0.769-0.188,1.153C0.275,58.289,0.625,58.5,1,58.5c0.046,0,0.092-0.003,0.139-0.01 c0.405-0.057,9.813-1.411,16.618-5.339C21.621,54.71,25.737,55.5,30,55.5c16.542,0,30-12.112,30-27S46.542,1.5,30,1.5z M16,32.5 c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S18.206,32.5,16,32.5z M30,32.5c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4 S32.206,32.5,30,32.5z M44,32.5c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S46.206,32.5,44,32.5z"}))},ke=function(){/*#__PURE__*/return T.default.createElement("svg",{className:"recycle-bin-icon",version:"1.1",xmlns:"http://www.w3.org/2000/svg",height:"15px",width:"15px",viewBox:"0 0 512 512"},/*#__PURE__*/T.default.createElement("g",null,/*#__PURE__*/T.default.createElement("g",null,/*#__PURE__*/T.default.createElement("path",{d:"M331.636,69.818V0H180.364v69.818h-128v128h34.909V512h337.455V197.818h34.909v-128H331.636z M215.273,34.909h81.455\nv34.909h-81.455V34.909z M389.818,477.091H122.182V197.818h267.636V477.091z M424.727,162.909H87.273v-58.182h337.455V162.909z"}))),/*#__PURE__*/T.default.createElement("g",null,/*#__PURE__*/T.default.createElement("g",null,/*#__PURE__*/T.default.createElement("rect",{x:"168.727",y:"256",width:"34.909",height:"162.909"}))),/*#__PURE__*/T.default.createElement("g",null,/*#__PURE__*/T.default.createElement("g",null,/*#__PURE__*/T.default.createElement("rect",{x:"308.364",y:"256",width:"34.909",height:"162.909"}))),/*#__PURE__*/T.default.createElement("g",null,/*#__PURE__*/T.default.createElement("g",null,/*#__PURE__*/T.default.createElement("rect",{x:"238.545",y:"256",width:"34.909",height:"162.909"}))))},Be="Unknown author",We=function(t){var n=e.useContext(se).options,r=e.useState(!1),o=r[0],a=r[1],s=e.useState(!1),i=s[0],u=s[1];q.default.addLocale(D.default),q.default.addLocale(H.default),q.default.setDefaultLocale(Y.LANG.en.locale);var l,c=new q.default(n.intl.locale),d=function(){if(n&&n.users){var e=n.users.find(function(e){return e.id===n.currentUser});if(t.author)return e.label?e.label:f()}return Be},f=function(){return t.author["@id"].replace(/.*[#\/]/,"... ")},p=function(){a(!o)};/*#__PURE__*/return T.default.createElement("div",{className:"comment-content",onMouseEnter:function(){u(!0)},onMouseLeave:function(){u(!1)}},/*#__PURE__*/T.default.createElement("div",{className:"row"},/*#__PURE__*/T.default.createElement("div",{className:"col-auto comment-author",onMouseEnter:p,onMouseLeave:p},/*#__PURE__*/T.default.createElement(T.default.Fragment,null,o?/*#__PURE__*/T.default.createElement(T.default.Fragment,null,d(),/*#__PURE__*/T.default.createElement(Qe,{iconClassContainer:"emphasise-on-relevant-icon",url:t.author?Object.values(t.author).toString():Be})):d())),/*#__PURE__*/T.default.createElement("div",{className:"col-auto text-muted comment-timestamp"},/*#__PURE__*/T.default.createElement(Me,{id:"exact-time-overlay",tooltipContent:(l=new Date(parseInt(t.timestamp)),new Intl.DateTimeFormat(n.intl.locale,{weekday:"long",year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}).format(l))},c.format(parseInt(t.timestamp)))),i?/*#__PURE__*/T.default.createElement(v.motion.div,{className:"comment-delete emphasise-on-relevant-icon",whileHover:{scale:1.2},whileTap:{scale:.9},onClick:function(){t.onDeleteQuestionComment(t.index),t.onDeleteViewComment()}},/*#__PURE__*/T.default.createElement(ke,null)):null),/*#__PURE__*/T.default.createElement("div",{className:"row"},/*#__PURE__*/T.default.createElement("div",{className:"col comment-value"},t.commentValue)))};We.propTypes={author:N.default.object,timestamp:N.default.string.isRequired,commentValue:N.default.string.isRequired,onDeleteQuestionComment:N.default.func.isRequired,onDeleteViewComment:N.default.func,index:N.default.number.isRequired};var Ge=function(t){var n=t.comments,r=t.onDeleteCommentClick,o=e.useRef(null),a=e.useState(!1),s=a[0],i=a[1],u=function(){i(!0),setTimeout(function(){i(!1)},2e3)};return e.useEffect(function(){null!==o.current&&(o.current.scrollTop=o.current.scrollHeight)},[JSON.stringify(n)]),p.jsx("span",{children:s?p.jsxs("div",{className:"comment-delete",children:[p.jsx(g.Rings,{color:"#00BFFF",height:80,width:80}),p.jsx("p",{children:"Deleting comment..."})]}):p.jsx("div",{className:"comment-list-items",ref:o,children:n.map(function(e,t){return p.jsx("div",{className:"comment-list-item",children:p.jsx(We,{commentValue:e[Y.HAS_COMMENT_VALUE],author:e[Y.HAS_AUTHOR]?e[Y.HAS_AUTHOR]:null,timestamp:e[Y.HAS_TIMESTAMP],onDeleteQuestionComment:r,onDeleteViewComment:u,index:t})},t)})})})},Xe=function(){/*#__PURE__*/return T.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"15",height:"15",viewBox:"0 0 24 24"},/*#__PURE__*/T.default.createElement("path",{d:"M6.185 4.843l11.927 7.157-11.927 7.157 2.982-7.157-2.982-7.157zm-4.185-4.843l5 12-5 12 20-12-20-12z"}))},Ye="300px",Je=function(t){var n=e.useState(""),r=n[0],o=n[1],a=e.useRef(null),i=S.useIntl();e.useEffect(function(){a.current.focus()},[]);var u=function(e){e.preventDefault(),t.onChange(r),o("")},l=function(){var e=a.current;e.style.height="auto",c(e)},c=function(e){e.style.height=e.scrollHeight+"px",parseInt(e.style.height)>parseInt(Ye)&&(e.style.height=Ye)};/*#__PURE__*/return T.default.createElement(s.Form,{onSubmit:u,onKeyUp:function(e){"Enter"===e.key&&e.ctrlKey&&r.trim()&&u(e)},onClick:function(e){e.stopPropagation()}},/*#__PURE__*/T.default.createElement(s.Form.Group,{className:"m-2",controlId:"formBasicComment"},/*#__PURE__*/T.default.createElement(s.Col,{className:"col-lg-12 p-0"},/*#__PURE__*/T.default.createElement(s.Row,{className:"container-fluid p-0 m-0"},/*#__PURE__*/T.default.createElement("div",{id:"comment-form"},/*#__PURE__*/T.default.createElement(s.Form.Control,{className:"comment-form-control",name:"comment",as:"textarea",placeholder:i.formatMessage({id:"comment.form.placeholder"}),required:!0,value:r,onChange:function(e){o(e.target.value)},ref:a,onKeyPress:l,onKeyDown:l}),/*#__PURE__*/T.default.createElement(s.Button,{className:"comment-form-button",variant:"primary",type:"submit"},/*#__PURE__*/T.default.createElement(Xe,null)))))))};Je.propTypes={onChange:N.default.func.isRequired};var Ke,Ze=function(){/*#__PURE__*/return T.default.createElement("svg",{className:"close-icon",width:"24px",height:"24px",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},/*#__PURE__*/T.default.createElement("path",{d:"M13.41 12l4.3-4.29a1 1 0 1 0-1.42-1.42L12 10.59l-4.29-4.3a1 1 0 0 0-1.42 1.42l4.3 4.29-4.3 4.29a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l4.29-4.3 4.29 4.3a1 1 0 0 0 1.42 0 1 1 0 0 0 0-1.42z"}))},$e=function(t){var n=e.useContext(se),r=e.useRef(null),o=e.useRef(null),a=e.useRef(null),i=e.useState(!1),u=i[0],l=i[1],c=e.useState("right"),d=c[0],f=c[1];e.useEffect(function(){_(a.current)});var p=function(){l(!1)},m=function(){var e=t.question;return e[Y.HAS_COMMENT]||(e[Y.HAS_COMMENT]=[]),Array.isArray(e[Y.HAS_COMMENT])||(e[Y.HAS_COMMENT]=[e[Y.HAS_COMMENT]]),e[Y.HAS_COMMENT]},h=function(e){var n={};E(n,e),t.onChange(A(),n)},E=function(e,t){n.options.currentUser&&(e[Y.HAS_AUTHOR]={"@id":n.options.currentUser}),e[Y.HAS_COMMENT_VALUE]=t,e[Y.HAS_TIMESTAMP]=Date.now().toString()},g=function(e){m().splice(e,1)},S=function(e){e.preventDefault(),e.stopPropagation()},A=function(){return m().length},_=function(e){e&&(e.getBoundingClientRect().x>window.innerWidth/2?f("left"):f("right"))};/*#__PURE__*/return T.default.createElement("div",{ref:a,onClick:S},/*#__PURE__*/T.default.createElement("span",{className:"comment-bubble",ref:r,onClick:function(e){S(e),l(!u)}},/*#__PURE__*/T.default.createElement(ze,null),A()>0?/*#__PURE__*/T.default.createElement(s.Badge,{className:"comment-badge",pill:!0,variant:"primary"},A()):null),/*#__PURE__*/T.default.createElement(v.motion.div,{className:"overlay-comment",ref:o,drag:!0,dragConstraints:{top:-50,left:-50,right:50,bottom:50}},/*#__PURE__*/T.default.createElement(s.Overlay,{target:r.current,show:u,placement:d,rootClose:!1,onHide:p,container:o},function(e){/*#__PURE__*/return T.default.createElement(s.Tooltip,j({className:"comment-tooltip"},e),/*#__PURE__*/T.default.createElement("span",{onKeyDown:function(e){!function(e){"Escape"===e.key&&p()}(e)}},/*#__PURE__*/T.default.createElement(v.motion.div,{className:"close-comment-icon",onClick:p,whileHover:{scale:1.1,transition:{duration:.1}}},/*#__PURE__*/T.default.createElement(Ze,null)),/*#__PURE__*/T.default.createElement(Ge,{comments:m(),onDeleteCommentClick:g}),/*#__PURE__*/T.default.createElement(Je,{onChange:h})))})))};$e.propTypes={question:N.default.object.isRequired,onChange:N.default.func.isRequired};var et=/*#__PURE__*/function(){function e(){}return e.renderIcons=function(e,t,n,r){var o;o=t.icons?t.icons:Y.DEFAULT_OPTIONS.icons;for(var a=[],s=this.renderQuestionHelp(e,t,n,r),i=this.renderQuestionComments(e,t,n,r),u=this.renderQuestionLink(e,t,n,r),l=0;l<o.length;l++)o[l].id===Y.ICONS.QUESTION_COMMENTS&&a.push(/*#__PURE__*/T.default.createElement("li",{key:l,className:"icon-list-item"},i)),o[l].id===Y.ICONS.QUESTION_HELP&&a.push(/*#__PURE__*/T.default.createElement("li",{key:l,className:"icon-list-item"},s)),o[l].id===Y.ICONS.QUESTION_LINK&&a.push(/*#__PURE__*/T.default.createElement("li",{key:l,className:"icon-list-item"},u));/*#__PURE__*/return T.default.createElement("ol",{className:"icon-list-items"},a)},e.renderQuestionHelp=function(e,t,n,r){return this.getIconComponentFromName(Y.ICONS.QUESTION_HELP,e,t,n,r)},e.renderQuestionLink=function(e,t,n,r){return this.getIconComponentFromName(Y.ICONS.QUESTION_LINK,e,t,n,r)},e.getIconComponentFromName=function(e,t,n,r,o){var a=this.getIconFromIconList(n.icons?n.icons:Y.DEFAULT_OPTIONS.icons,e);return this.getIconComponent(a,t,n,r,o)},e.getIconComponent=function(e,t,n,r,o){var a;if(e&&(e.behavior===Y.ICON_BEHAVIOR.ON_HOVER||e.behavior===Y.ICON_BEHAVIOR.ENABLE))return e.behavior===Y.ICON_BEHAVIOR.ENABLE?(o=!0,a=""):a="emphasise-on-relevant-icon",e.id===Y.ICONS.QUESTION_HELP&&t[Y.HELP_DESCRIPTION]?o?/*#__PURE__*/T.default.createElement("div",{className:a},/*#__PURE__*/T.default.createElement(Pe,{text:I.default.getLocalized(t[Y.HELP_DESCRIPTION],n.intl),absolutePosition:!1})):null:e.id===Y.ICONS.QUESTION_LINK&&t[Y.SOURCE]?o?/*#__PURE__*/T.default.createElement("div",{className:a},/*#__PURE__*/T.default.createElement(Qe,{url:t[Y.SOURCE]})):null:e.id===Y.ICONS.QUESTION_COMMENTS&&o?/*#__PURE__*/T.default.createElement("div",{className:a},/*#__PURE__*/T.default.createElement($e,{question:t,onChange:r})):null},e}();Ke=et,et.renderQuestionComments=function(e,t,n,r){return Ke.getIconComponentFromName(Y.ICONS.QUESTION_COMMENTS,e,t,n,r)},et.getIconFromIconList=function(e,t){return e?e.find(function(e){return e.id===t}):null};var tt=function(e){var t,n,r=T.default.useContext(G),o=T.default.useContext(se).options,a=function(t){var n=Object.assign({},e.answer);s(n,t),e.onChange(e.index,n)},s=function(t,n){null===n?(t[Y.HAS_OBJECT_VALUE]=null,t[Y.HAS_DATA_VALUE]=null):e.answer[Y.HAS_OBJECT_VALUE]||$.isTypeahead(e.question)?t[Y.HAS_OBJECT_VALUE]={"@id":n}:t[Y.HAS_DATA_VALUE]={"@value":n}},i=e.question,u=$.resolveValue(e.answer),l=function(t){var n=I.default.getLocalized(t[Y.RDFS_LABEL],o.intl);/*#__PURE__*/return T.default.createElement("div",{className:"question-header"},n,et.renderIcons(e.question,o,e.onCommentChange,e.showIcon))}(i),c=I.default.getLocalized(i[Y.RDFS_COMMENT],o.intl);return t=$.isTypeahead(i)?function(t,n,o){var s=J.getStringHash($.getPossibleValuesQuery(e.question)),i=r.getOptions(s)||[];/*#__PURE__*/return T.default.createElement(He,{question:e.question,answer:e.answer,label:n,title:o,value:t,onChange:a,options:i})}(u,l,c):(n=i)[Y.HAS_OPTION]&&0!==n[Y.HAS_OPTION].length?function(t,n,r){/*#__PURE__*/return T.default.createElement(Re,{question:e.question,label:n,title:r,value:t,onChange:a})}(u,l,c):$.isCalendar(i)?function(t,n,r){/*#__PURE__*/return T.default.createElement(Se,{question:e.question,value:t,title:r,label:n,onChange:a})}(u,l,c):$.isCheckbox(i)?function(t,n,r){/*#__PURE__*/return T.default.createElement(ge,{label:n,title:r,value:t,onChange:a,question:e.question})}(u,l,c):$.isMaskedInput(i)?function(t,n,r){/*#__PURE__*/return T.default.createElement(Le,{label:n,title:r,value:t,onChange:a,question:e.question,answer:e.answer})}(u,l,c):$.isSparqlInput(i)?function(t,n,r){/*#__PURE__*/return T.default.createElement(Ne,{question:e.question,answer:e.answer,label:n,title:r,value:t,onChange:a,sparql:!0})}(u,l,c):$.isTurtleInput(i)?function(t,n,r){/*#__PURE__*/return T.default.createElement(Ne,{question:e.question,answer:e.answer,label:n,title:r,value:t,onChange:a,turtle:!0})}(u,l,c):function(t,n,r){/*#__PURE__*/return T.default.createElement(Ne,{question:e.question,answer:e.answer,label:n,title:r,value:t,onChange:a})}(u,l,c),t};tt.propTypes={answer:N.default.object.isRequired,question:N.default.object.isRequired,onChange:N.default.func.isRequired,onCommentChange:N.default.func.isRequired,index:N.default.number,icons:N.default.object};var nt=/*#__PURE__*/function(){function e(){}return e.createValidator=function(t,n){return t[Y.REQUIRES_ANSWER]?$.isCheckbox(t)?e._generateRequiresAnswerCheckBoxValidator(t,n):e._generateRequiresAnswerValidator(t,n):function(){var e={};return e[Y.HAS_VALID_ANSWER]=!0,delete e[Y.HAS_VALIDATION_MESSAGE],e}},e._generateRequiresAnswerValidator=function(e,t){return function(n){var r=null;n[Y.HAS_DATA_VALUE]?r=I.default.getJsonAttValue(n,Y.HAS_DATA_VALUE):n[Y.HAS_OBJECT_VALUE]&&(r=I.default.getJsonAttValue(n,Y.HAS_OBJECT_VALUE,"@id"));var o=null!=r&&""!==r,a={};return a[Y.HAS_VALID_ANSWER]=o,a[Y.HAS_VALIDATION_MESSAGE]=o?null:I.default.getLocalized(e[I.default.RDFS_LABEL],t)+" is missing a value.",a}},e._generateRequiresAnswerCheckBoxValidator=function(e,t){return function(n){var r=null;n[Y.HAS_DATA_VALUE]?r=I.default.getJsonAttValue(n,Y.HAS_DATA_VALUE):n[Y.HAS_OBJECT_VALUE]&&(r=I.default.getJsonAttValue(n,Y.HAS_OBJECT_VALUE,"@id"));var o=null!=r&&""!==r&&!1!==r,a={};return a[Y.HAS_VALID_ANSWER]=o,a[Y.HAS_VALIDATION_MESSAGE]=o?null:I.default.getLocalized(e[I.default.RDFS_LABEL],t)+" must be checked.",a}},e}(),rt=/*#__PURE__*/function(e){function t(t){var n;return(n=e.call(this,t)||this).state={prefixes:t.prefixes},n}return M(t,e),t.prototype.render=function(){var e=/*#__PURE__*/T.default.createElement(s.Popover,{id:"prefixes",title:"Prefixes"},/*#__PURE__*/T.default.createElement(s.ListGroup,null,this.state.prefixes.sort(function(e,t){return e[Y.PREFIX]<t[Y.PREFIX]?-1:1}).map(function(e){/*#__PURE__*/return T.default.createElement(s.ListGroupItem,{key:e[Y.PREFIX]},/*#__PURE__*/T.default.createElement("strong",null,e[Y.PREFIX]),": ",e[Y.NAMESPACE])})));/*#__PURE__*/return T.default.createElement(s.OverlayTrigger,{trigger:"click",placement:"right",overlay:e},/*#__PURE__*/T.default.createElement("span",{className:this.props.iconClass},this.props.children))},t}(T.default.Component);rt.propTypes={prefixes:N.default.array.isRequired,children:N.default.element.isRequired,iconClass:N.default.string},rt.defaultProps={iconClass:""};var ot=function(e){var t;return(t=e.question[Y.HAS_MEDIA_CONTENT])?Array.isArray(t)?p.jsx("div",{className:"col-6",children:t.map(function(e,n){return p.jsx("div",{className:"row embed-responsive-21by9 media-content-video-container mb-3",children:p.jsx("iframe",{src:t[n],className:"embed-responsive-item",allowFullScreen:!0})},n)})}):p.jsx("div",{className:"col-6",children:p.jsx("iframe",{src:t,className:"embed-responsive-item",allowFullScreen:!0})}):null},at=/*#__PURE__*/function(e){function t(n){var r;return(r=e.call(this,n)||this).handleAnswerChange=function(e,t){if($.isSection(r.props.question)){var n=!!$.resolveValue(t);r.setState({expanded:n})}r._handleChange(Y.HAS_ANSWER,e,t)},r.handleSubQuestionChange=function(e,t){r._handleChange(Y.HAS_SUBQUESTION,e,t)},r.handleCommentChange=function(e,t){r._handleChange(Y.HAS_COMMENT,e,t)},r._toggleCollapse=function(){r.props.collapsible&&r.setState({expanded:!r.state.expanded})},r._onMouseEnterHandler=function(){r.setState({showIcon:!0})},r._onMouseLeaveHandler=function(){r.setState({showIcon:!1})},r._getHeaderClassName=function(){var e=r.props.question,n=r.props.collapsible,o=[];return o.push(t.getEmphasizedOnRelevantClass(e),"question-header"),$.isWizardStep(e)&&o.push("wizard-step bg-primary text-white"),$.isEmphasised(e)&&o.push(t.getEmphasizedClass(e)),$.isSection(e)&&o.push("section-background"),n&&o.push("cursor-pointer"),r.isDebugged(e)&&o.push("show-irrelevant"),o},K.putObject(n.question["@id"],n.question),r.state={validator:null,expanded:!$.isCollapsed(n.question),showIcon:!1},r}M(t,e);var n=t.prototype;return n.componentDidMount=function(){this.setState({validator:nt.createValidator(this.props.question,this.context.options.intl)})},n.componentDidUpdate=function(){var e=this.props.question,t=this.context.options.startingQuestionId,n=e[Y.HAS_SUBQUESTION].find(function(e){return e["@id"]===t});if($.isSection(e)&&$.isAnswerable(e)){var r=this._getFirstAnswerValue();if(this.context.options.debugMode)return null;if(n)return null;this.state.expanded&&!r&&this.setState({expanded:!1})}},n._handleChange=function(e,t,n){var r=Object.assign({},this.props.question);if(r[e][t]=n,e===Y.HAS_ANSWER){var o=this.state.validator(n);r=Object.assign({},r,o)}K.putObject(r["@id"],r),this.props.onChange(this.props.index,r)},n.isDebugged=function(e){var t=this.context.options.startingQuestionId;return!$.isRelevant(e)&&(!!this.context.options.debugMode||null!=t&&!!J.findQuestionById(t,e,!0,!1,!1))},n.render=function(){var e=this.props.question,t=this.renderQuestion(e);return this.isDebugged(e)?/*#__PURE__*/T.default.createElement("div",{className:"show-irrelevant"},t):$.isHidden(e)?null:$.isRelevant(e)?t:null},n.renderQuestion=function(e){if($.isAnswerable(e)&&!$.isSection(e))/*#__PURE__*/return T.default.createElement("div",{id:e["@id"]},/*#__PURE__*/T.default.createElement("div",{className:"panel-title answerable-question"},this.renderAnswers()),/*#__PURE__*/T.default.createElement("div",{className:"answerable-subquestions"},this.renderSubQuestions()));if($.isAnswerable(e))return this.renderAnswerableSection();if($.isSection(e)){var n=this.props,r=n.collapsible,o=n.withoutCard,a=t._getQuestionCategoryClass(e);if(o)/*#__PURE__*/return T.default.createElement("div",null,this._renderQuestionContent());var i=I.default.getLocalized(e[I.default.RDFS_LABEL],this.context.options.intl),u=/*#__PURE__*/T.default.createElement(s.Card.Body,{className:U.default("p-3",a)},this._renderQuestionContent());/*#__PURE__*/return T.default.createElement(T.default.Fragment,null,/*#__PURE__*/T.default.createElement(s.Accordion,{defaultActiveKey:this.state.expanded?void 0:i},/*#__PURE__*/T.default.createElement(s.Card,{className:"mb-3"},/*#__PURE__*/T.default.createElement(s.Accordion.Toggle,{as:s.Card.Header,onClick:this._toggleCollapse,className:this._getHeaderClassName(),onMouseEnter:this._onMouseEnterHandler,onMouseLeave:this._onMouseLeaveHandler},/*#__PURE__*/T.default.createElement("h6",{className:"d-inline",id:e["@id"]},r&&!$.isWizardStep(e)&&this._renderCollapseToggle(),i),this.renderQuestionIcons(),this.props.children),/*#__PURE__*/T.default.createElement(r?s.Accordion.Collapse:T.default.Fragment,null,u))))}/*#__PURE__*/return T.default.createElement("div",null,this._renderQuestionContent())},n._renderQuestionContent=function(){var e=[];return this.state.expanded&&e.push(/*#__PURE__*/T.default.createElement(ot,{key:this.props.question["@id"]+"-media",question:this.props.question})),e.push(this.renderAnswers()),e.push(this.renderSubQuestions()),e},n.renderQuestionIcons=function(){return et.renderIcons(this.props.question,this.context.options,this.handleCommentChange,this.state.showIcon)},n.renderAnswerableSection=function(){var e=this.props.question,n=this.props.collapsible,r=t._getQuestionCategoryClass(e),o=this.getShowIrrelevantClassname(e),a=/*#__PURE__*/T.default.createElement(s.Card.Body,{className:U.default("p-3",r)},this.renderSubQuestions(o));/*#__PURE__*/return T.default.createElement(s.Accordion,{activeKey:this.state.expanded?e["@id"]:void 0,className:"answerable-section"},/*#__PURE__*/T.default.createElement(s.Card,{className:"mb-3"},/*#__PURE__*/T.default.createElement(s.Card.Header,{onClick:this._toggleCollapse,className:this._getHeaderClassName()},this.renderAnswers()),n?/*#__PURE__*/T.default.createElement(s.Accordion.Collapse,{className:o,eventKey:e["@id"]},a):{cardBody:a}))},n.getShowIrrelevantClassname=function(e){return!this.context.options.debugMode&&!Z.checkId(e[Y.HAS_SUBQUESTION],this.context.options.startingQuestionId)||$.hasAnswer(e)?"":"show-irrelevant"},n.renderAnswers=function(){for(var e,n=this.props.question,r=[],o=this._getAnswers(),a=0,s=o.length;a<s;a++)$.isTextarea(n,$.resolveValue(o[a]))||$.isSparqlInput(n)||$.isTurtleInput(n),e=U.default("answer",t._getQuestionCategoryClass(n),t.getEmphasizedOnRelevantClass(n)),r.push(/*#__PURE__*/T.default.createElement("div",{key:"row-item-"+a,className:e,id:n["@id"],onMouseEnter:this._onMouseEnterHandler,onMouseLeave:this._onMouseLeaveHandler},/*#__PURE__*/T.default.createElement("div",{className:"answer-content",style:this._getAnswerWidthStyle()},/*#__PURE__*/T.default.createElement(tt,{index:a,answer:o[a],question:n,onChange:this.handleAnswerChange,onCommentChange:this.handleCommentChange,showIcon:this.state.showIcon})),this._renderUnits(),this._renderPrefixes()));return r},n._getAnswers=function(){var e=this.props.question;return e[Y.HAS_ANSWER]||(e[Y.HAS_ANSWER]=[]),Array.isArray(e[Y.HAS_ANSWER])||(e[Y.HAS_ANSWER]=[e[Y.HAS_ANSWER]]),0===e[Y.HAS_ANSWER].length&&(e[Y.HAS_ANSWER]=$.isSection(e)&&!$.isAnswerable(e)?[]:[Ee.generateAnswer(e)]),e[Y.HAS_ANSWER]},n._getAnswerWidthStyle=function(){var e=Number(this.props.question[Y.HAS_INITIAL_INPUT_LENGTH]);return e?{flexGrow:0,maxWidth:"none",width:"calc("+e+"ch + 1.5rem + 2px)"}:{}},t._getAnswerClass=function(e,t){return t?"col-12":1===Y.GENERATED_ROW_SIZE?"col-6":"col-"+Y.COLUMN_COUNT/Y.GENERATED_ROW_SIZE},t._getQuestionCategoryClass=function(e){var t=$.getCategory(e);return t?"question-"+t:""},t.getEmphasizedClass=function(e){return $.isEmphasised(e)?"bg-warning":""},t.getEmphasizedOnRelevantClass=function(e){return I.default.hasValue(e,Y.LAYOUT_CLASS,Y.LAYOUT.EMPHASISE_ON_RELEVANT)?"emphasise-on-relevant":""},n._renderCollapseToggle=function(){var e=this.context.options,t=this.state.expanded?e.i18n["section.collapse"]:e.i18n["section.expand"];/*#__PURE__*/return T.default.createElement("span",{onClick:this._toggleCollapse,title:t},/*#__PURE__*/T.default.createElement(this.state.expanded?De:Ue,{title:t}))},n._renderPrefixes=function(){var e=this.props.question;return e[Y.HAS_DECLARED_PREFIX]&&e[Y.HAS_DECLARED_PREFIX].length?/*#__PURE__*/T.default.createElement(rt,{prefixes:e[Y.HAS_DECLARED_PREFIX],iconClass:"help-icon-checkbox"},/*#__PURE__*/T.default.createElement(Ve,null)):null},n._renderUnits=function(){var e=this.props.question;return e[Y.HAS_UNIT]?/*#__PURE__*/T.default.createElement("div",{className:"has-unit-label"},e[Y.HAS_UNIT]):null},n.renderSubQuestions=function(e){for(var n=[],r=this._getSubQuestions(),o=this.context.options.debugMode,a=this.context.options.startingQuestionId,s=0;s<r.length;s++){var i=r[s],u=this.context.mapComponent(i,t),l=null;(o||"show-irrelevant"!==e||J.findQuestionById(a,i,!0,!1,!1))&&(l=/*#__PURE__*/T.default.createElement(u,{key:"sub-question-"+s,question:i,onChange:this.handleSubQuestionChange,index:s})),n.push(l)}return n},n._getSubQuestions=function(){var e=this.props.question;return e[Y.HAS_SUBQUESTION]||(e[Y.HAS_SUBQUESTION]=[]),Array.isArray(e[Y.HAS_SUBQUESTION])||(e[Y.HAS_SUBQUESTION]=[e[Y.HAS_SUBQUESTION]]),Z.orderByLocalizedLabels(e[Y.HAS_SUBQUESTION],this.context.options.intl),Z.orderPreservingToplogicalSort(e[Y.HAS_SUBQUESTION],Y.HAS_PRECEDING_QUESTION),e[Y.HAS_SUBQUESTION]},n._getFirstAnswerValue=function(){return $.resolveValue(this._getAnswers()[0])},t}(T.default.Component);at.contextType=se,at.propTypes={question:N.default.object.isRequired,onChange:N.default.func.isRequired,index:N.default.number,withoutCard:N.default.bool,collapsible:N.default.bool},at.defaultProps={withoutCard:!1,collapsible:!0};var st=/*#__PURE__*/function(e){function t(t){var n;return(n=e.call(this,t)||this).onNextStep=function(){n.context.updateFormQuestionsData(n.props.index,n.context.getFormQuestionsData()),n.props.onNextStep()},n.onPreviousStep=function(){n.props.onPreviousStep()},n._renderWizardStepButtons=function(){/*#__PURE__*/return T.default.createElement(s.ButtonToolbar,{className:"m-3 float-right"},!n.props.isFirstStep&&/*#__PURE__*/T.default.createElement(s.Button,{className:"mr-2",onClick:n.onPreviousStep,variant:"primary",size:"sm"},n.props.options.i18n["wizard.previous"]),!n.props.isLastStep&&/*#__PURE__*/T.default.createElement(s.Button,{onClick:n.onNextStep,variant:"primary",size:"sm"},n.props.options.i18n["wizard.next"]))},n.onChange=function(e,t){n.context.updateFormQuestionsData(n.props.index||e,Object.assign({},n.props.question,t))},n}return M(t,e),t.prototype.render=function(){var e=this.context.getFormQuestionsData([this.props.index]);/*#__PURE__*/return T.default.createElement(T.default.Fragment,null,/*#__PURE__*/T.default.createElement(at,{question:e,onChange:this.onChange,collapsible:$.isAnswerable(e)}),this.props.options.wizardStepButtons&&this._renderWizardStepButtons())},t}(T.default.Component);st.propTypes={options:N.default.object.isRequired,question:N.default.object.isRequired,index:N.default.number.isRequired,onNextStep:N.default.func,onPreviousStep:N.default.func,mapComponent:N.default.func,isFirstStep:N.default.bool,isLastStep:N.default.bool},st.contextType=ne;var it=function(t){var n=t.steps,r=t.onNavigate,o=t.currentStep,a=e.useContext(se).options;/*#__PURE__*/return T.default.createElement(s.Card.Header,null,/*#__PURE__*/T.default.createElement(s.Nav,{variant:"tabs",activeKey:o,onSelect:function(e){return r(parseInt(e))}},n.map(function(e,t){/*#__PURE__*/return T.default.createElement(s.NavItem,{key:"nav"+t,id:"wizard-nav-"+t},/*#__PURE__*/T.default.createElement(s.NavLink,{eventKey:t,active:t===o?"active":"",hidden:!a.debugMode&&!$.isRelevant(e),className:U.default([a.debugMode&&!$.isRelevant(e)?"show-irrelevant":at.getEmphasizedClass(e),"wizard-nav"])},I.default.getLocalized(e[I.default.RDFS_LABEL],a.intl)))})))};it.propTypes={currentStep:N.default.number.isRequired,steps:N.default.array.isRequired,onNavigate:N.default.func.isRequired};var ut=function(t){var n=t.steps,r=t.onNavigate,o=t.currentStep,a=e.useContext(se).options;/*#__PURE__*/return T.default.createElement("div",{className:"wizard-nav col-2 p-0"},/*#__PURE__*/T.default.createElement(s.ListGroup,null,n.map(function(e,t){/*#__PURE__*/return T.default.createElement(s.ListGroupItem,{hidden:!a.debugMode&&!$.isRelevant(e),key:"nav"+t,onClick:function(){return r(t)},id:"wizard-nav-"+t,action:!0,active:t===o?"active":"",variant:"default",className:U.default([a.debugMode&&!$.isRelevant(e)?"show-irrelevant":at.getEmphasizedClass(e),"wizard-nav"])},I.default.getLocalized(e[I.default.RDFS_LABEL],a.intl))})))};ut.propTypes={currentStep:N.default.number.isRequired,steps:N.default.array.isRequired,onNavigate:N.default.func.isRequired};var lt=function(e,t){var n=function e(n,r){return n?n["@id"]===t?r:J.asArray(n[Y.HAS_SUBQUESTION]).findIndex(function(t,n){return-1!==e(t,n)}):-1};return e.findIndex(function(e,t){return-1!==n(e,t)})},ct=function(){var t=T.default.useContext(ne),n=T.default.useContext(se),r=n.options,o=n.mapComponent,a=0;r.startingQuestionId?-1===(a=lt(t.getFormQuestionsData(),r.startingQuestionId))&&(console.warn("Question with id "+r.startingQuestionId+" not found!"),a=0):r.startingStep&&(a=r.startingStep<t.getFormQuestionsData().length?r.startingStep:0);var i=T.default.useState(a),u=i[0],l=i[1],c=T.default.useState(!1),d=c[0],f=c[1];e.useEffect(function(){if(r.startingQuestionId&&!d){var e=document.getElementById(r.startingQuestionId);e&&(e.scrollIntoView(),e.classList.add("text-danger"),f(!0))}});var p,m=null;t.getFormQuestionsData().length>1&&(p=t.getFormQuestionsData(),m=/*#__PURE__*/T.default.createElement(r.horizontalWizardNav?it:ut,{currentStep:u,steps:p,onNavigate:function(e){var n=t.getFormQuestionsData();e===u||e>=n.length||e>u&&!n[e].visited&&!r.enableForwardSkip||l(e)}}));var h,E,v=r.horizontalWizardNav;/*#__PURE__*/return T.default.createElement(s.Card,{className:v?"":"flex-row p-3"},m,/*#__PURE__*/T.default.createElement("div",{className:v?"card-body p-3":m?"col-10 p-0 pl-3":"col-12 p-0"},(E=o(h=t.getFormQuestionsData()[u],st),/*#__PURE__*/T.default.createElement(E,{options:r,key:"step"+u,question:h,onNextStep:function(){var e=t.getFormQuestionsData();u!==e.length-1&&(e[u+1].visited=!0,l(function(e){return e+1}))},onPreviousStep:function(){0!==u&&l(function(e){return e-1})},mapComponent:o,index:u,isFirstStep:0===u,isLastStep:u===t.getFormQuestionsData().length-1}))))},dt=/*#__PURE__*/T.default.forwardRef(function(e,t){var n=T.default.useContext(se).options;/*#__PURE__*/return T.default.createElement(s.Modal,j({size:"xl",animation:!0},n.modalProps),/*#__PURE__*/T.default.createElement(s.Modal.Header,{closeButton:!0},/*#__PURE__*/T.default.createElement(s.Modal.Title,null,n.modalProps.title)),/*#__PURE__*/T.default.createElement(s.Modal.Body,{className:"overflow-hidden p-0"},e.children))});dt.propTypes={children:N.default.element.isRequired};var ft=/*#__PURE__*/function(e){function t(){for(var t,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(t=e.call.apply(e,[this].concat(r))||this).getFormData=function(){var e=t.context.getData(),n=t.context.getFormQuestionsData();return Ee.buildQuestionAnswerModel(e,n)},t.getFormQuestionsData=function(){return t.context.getFormQuestionsData()},t.handleStepChange=function(e,n,r){t.context.updateFormQuestionsData(n,Object.assign({},e,r))},t.renderWizardlessForm=function(){var e=t.context.getFormQuestionsData();/*#__PURE__*/return T.default.createElement(V.default,{className:"p-3"},e.map(function(e,n){return t._mapQuestion(e,n)}))},t}M(t,e);var n=t.prototype;return n._mapQuestion=function(e,t){var n=this,r=this.props.mapComponent(e,at);/*#__PURE__*/return T.default.createElement(r,{key:e["@id"],question:e,onChange:function(t,r){return n.handleStepChange(e,t,r)},index:t})},n.render=function(){var e=this.props.modalView,t=this.context.getFormQuestionsData();if(!t.length)/*#__PURE__*/return T.default.createElement(V.default,{className:"p-3 font-italic"},"There are no questions available...");var n=t.every(function(e){return!$.isWizardStep(e)});return e?/*#__PURE__*/T.default.createElement(dt,null,n?this.renderWizardlessForm():/*#__PURE__*/T.default.createElement(ct,null)):n?this.renderWizardlessForm():/*#__PURE__*/T.default.createElement(ct,null)},t}(T.default.Component);ft.contextType=ne;var pt=/*#__PURE__*/e.forwardRef(function(t,n){var r=e.useState(!0),o=r[0],a=r[1],i=e.useState(null),u=i[0],l=i[1],c=e.useState(null),d=c[0],f=c[1];if(e.useEffect(function(){!function(){try{return Promise.resolve(he.constructForm(t.form,t.options.intl)).then(function(e){var t=e[0],n=e[1];t.formQuestions.some(function(e){return $.isWizardStep(e)})&&(t.formQuestions[0].visited=!0),l(t),f(n),a(!1)})}catch(e){return Promise.reject(e)}}()},[t.form]),o)return t.loader||/*#__PURE__*/T.default.createElement(s.Card,{className:"p-3 font-italic"},"Loading SForms...");var p=function(e,t){return function(n,r){if(!e)return r;for(var o,a=z(e);!(o=a()).done;){var s=o.value,i=s.component;if((0,s.mapRule)(n,t))return i}return r}}(t.componentMapRules,d);/*#__PURE__*/return T.default.createElement(ue,{components:t.components,componentsOptions:t.componentsOptions,mapComponent:p,options:t.options},/*#__PURE__*/T.default.createElement(X,{fetchTypeAheadValues:t.fetchTypeAheadValues},/*#__PURE__*/T.default.createElement(re,{data:d,formQuestions:u.formQuestions,isFormValid:t.isFormValid},/*#__PURE__*/T.default.createElement(ft,{ref:n,modalView:t.options&&t.options.modalView,mapComponent:p}))))});pt.propTypes={form:N.default.object.isRequired,options:N.default.object.isRequired,componentMapRules:N.default.array,components:N.default.object,componentsOptions:N.default.object,fetchTypeAheadValues:N.default.func,isFormValid:N.default.func,loader:N.default.element};var mt={"comment.form.placeholder":"Sem napište své komentáře (Ctrl+Enter pro potvrzení)"},ht={"comment.form.placeholder":"Write your comments here (Ctrl+Enter to confirm, Esc to cancel)"},Et=/*#__PURE__*/T.default.createContext({});exports.Answer=tt,exports.ConfigurationContext=se,exports.Constants=Y,exports.FormQuestionsContext=ne,exports.FormUtils=$,exports.HelpIcon=Pe,exports.IntlContextProvider=function(e){var t=e.locale,n=void 0===t?navigator.language:t,r=ht;return n===Y.LANG.cs.locale&&(r=mt),p.jsx(Et.Provider,{value:{locale:n,lang:r},children:p.jsx(S.IntlProvider,{locale:n,messages:r,children:e.children})})},exports.JsonLdFramingUtils=me,exports.JsonLdObjectMap=K,exports.JsonLdObjectUtils=Z,exports.Question=at,exports.QuestionStatic=et,exports.WizardStep=st,exports.default=pt;
3729
2
  //# sourceMappingURL=s-forms.cjs.map