@kbss-cvut/s-forms
Version:
Semantic forms generator and processor
1 lines • 105 kB
JavaScript
import e,{useMemo as t,useState as n,useEffect as o,useContext as s,useRef as r,useCallback as i,forwardRef as a,useImperativeHandle as l}from"react";import*as c from"jsonld-utils";import{IntlProvider as u,useIntl as d}from"react-intl";import"core-js/modules/es.array.iterator.js";import"core-js/modules/es.promise.js";import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.array.sort.js";import*as m from"jsonld";import"core-js/modules/es.array.includes.js";import"core-js/modules/es.string.includes.js";import p from"@kbss-cvut/tsort";import"core-js/modules/esnext.set.add-all.js";import"core-js/modules/esnext.set.delete-all.js";import"core-js/modules/esnext.set.difference.js";import"core-js/modules/esnext.set.every.js";import"core-js/modules/esnext.set.filter.js";import"core-js/modules/esnext.set.find.js";import"core-js/modules/esnext.set.intersection.js";import"core-js/modules/esnext.set.is-disjoint-from.js";import"core-js/modules/esnext.set.is-subset-of.js";import"core-js/modules/esnext.set.is-superset-of.js";import"core-js/modules/esnext.set.join.js";import"core-js/modules/esnext.set.map.js";import"core-js/modules/esnext.set.reduce.js";import"core-js/modules/esnext.set.some.js";import"core-js/modules/esnext.set.symmetric-difference.js";import"core-js/modules/esnext.set.union.js";import{Form as h,FormGroup as E,FormControl as A,Alert as g,Accordion as S,Card as f,Button as v,OverlayTrigger as _,Tooltip as T,Col as N,Row as O,Badge as I,Overlay as C,FormText as b,Popover as R,ListGroup as L,ListGroupItem as y,ButtonToolbar as w,Nav as H,NavItem as D,NavLink as V,Modal as M}from"react-bootstrap";import"core-js/modules/es.object.assign.js";import U from"prop-types";import x from"react-dom";import"core-js/modules/es.regexp.to-string.js";import P from"react-datepicker";import{parse as q,format as k}from"date-fns";import F from"classnames";import z from"yasgui-yasqe";import"@triply/yasgui/build/yasgui.min.css";import j from"inputmask-core";import"core-js/modules/es.string.trim.js";import{IntelligentTreeSelect as Q}from"intelligent-tree-select/lib/components/IntelligentTreeSelect";import B from"intelligent-tree-select/lib/components/Option";import"intelligent-tree-select/lib/styles.css";import"core-js/modules/es.regexp.exec.js";import"core-js/modules/es.string.replace.js";import W from"javascript-time-ago";import Y from"javascript-time-ago/locale/en";import X from"javascript-time-ago/locale/cs";import{motion as G}from"framer-motion";import{Rings as K}from"react-loader-spinner";import"core-js/modules/es.parse-int.js";import"core-js/modules/es.regexp.constructor.js";import"core-js/modules/es.parse-float.js";import"core-js/modules/es.string.split.js";import"video.js/dist/video-js.css";import"core-js/modules/es.array.reduce.js";import J from"video.js";function $(){return $=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)({}).hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},$.apply(null,arguments)}function Z(e,t){if(null==e)return{};var n={};for(var o in e)if({}.hasOwnProperty.call(e,o)){if(-1!==t.indexOf(o))continue;n[o]=e[o]}return n}var ee;class te{}ee=te,te.COLUMN_COUNT=12,te.INPUT_LENGTH_THRESHOLD=50,te.DATETIME_NUMBER_FORMAT="x",te.EPOCH_MILLISECONDS="epoch-milliseconds",te.FORM="http://onto.fel.cvut.cz/ontologies/documentation/form",te.HAS_SUBQUESTION="http://onto.fel.cvut.cz/ontologies/documentation/has_related_question",te.HAS_ANSWER="http://onto.fel.cvut.cz/ontologies/documentation/has_answer",te.HAS_OPTION="http://onto.fel.cvut.cz/ontologies/form/has-possible-value",te.HAS_OPTIONS_QUERY="http://onto.fel.cvut.cz/ontologies/form/has-possible-values-query",te.HAS_VALUE_TYPE="http://onto.fel.cvut.cz/ontologies/form/has-value-type",te.IS_DISABLED="http://onto.fel.cvut.cz/ontologies/aviation/form-376/is-disabled",te.INPUT_MASK="http://onto.fel.cvut.cz/ontologies/form/has-input-mask",te.LAYOUT_CLASS="http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class",te.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"]},te.HAS_INITIAL_INPUT_LENGTH="http://onto.fel.cvut.cz/ontologies/form-layout/has-initial-input-length",te.VALUE_TYPE_CODE="code",te.VALUE_TYPE_TEXT="text",te.GENERATED_ROW_SIZE=1,te.HAS_QUESTION_ORIGIN="http://onto.fel.cvut.cz/ontologies/form/has-question-origin",te.HAS_ANSWER_ORIGIN="http://onto.fel.cvut.cz/ontologies/form/has-answer-origin",te.HAS_DATA_VALUE="http://onto.fel.cvut.cz/ontologies/documentation/has_data_value",te.HAS_OBJECT_VALUE="http://onto.fel.cvut.cz/ontologies/documentation/has_object_value",te.HELP_DESCRIPTION="http://purl.org/dc/terms/description",te.SOURCE="http://purl.org/dc/terms/source",te.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",FLOAT:"http://www.w3.org/2001/XMLSchema#float",POSITIVE_FLOAT:"http://www.w3.org/2001/XMLSchema#positiveFloat",NEGATIVE_FLOAT:"http://www.w3.org/2001/XMLSchema#negativeFloat",BOOLEAN:"http://www.w3.org/2001/XMLSchema#boolean"},te.STEP="http://onto.fel.cvut.cz/ontologies/form/step",te.PATTERN="http://onto.fel.cvut.cz/ontologies/form/pattern",te.ACCEPTS_ANSWER_VALUE="http://onto.fel.cvut.cz/ontologies/form/accepts-answer-value",te.ACCEPTS="http://onto.fel.cvut.cz/ontologies/form/accepts",te.HAS_DATATYPE="http://onto.fel.cvut.cz/ontologies/form/has-datatype",te.HAS_LAYOUT_CLASS="http://onto.fel.cvut.cz/ontologies/form/has-layout-class",te.HAS_POSSIBLE_VALUES_QUERY="http://onto.fel.cvut.cz/ontologies/form/has-possible-values-query",te.HAS_REQUIRED_VALUE="http://onto.fel.cvut.cz/ontologies/form/has-required-value",te.HAS_TESTED_QUESTION="http://onto.fel.cvut.cz/ontologies/form/has-tested-question",te.HAS_TESTED_FORM="http://onto.fel.cvut.cz/ontologies/form/has-tested-form",te.HAS_UNIT="http://onto.fel.cvut.cz/ontologies/form/has-unit",te.HAS_VALID_ANSWER="http://onto.fel.cvut.cz/ontologies/form/has-valid-answer",te.HAS_CORRECT_ANSWER="http://onto.fel.cvut.cz/ontologies/form/has-correct-answer-value",te.IS_RELEVANT_IF="http://onto.fel.cvut.cz/ontologies/form/is-relevant-if",te.ACCEPTS_VALIDATION_VALUE="http://onto.fel.cvut.cz/ontologies/form/accepts-validation-value",te.HAS_VALIDATION_MESSAGE="http://onto.fel.cvut.cz/ontologies/form/has-validation-message",te.NEGATIVE_CONDITION="http://onto.fel.cvut.cz/ontologies/form/negative-condition",te.REQUIRES_ANSWER="http://onto.fel.cvut.cz/ontologies/form/requires-answer",te.USED_ONLY_FOR_COMPLETENESS="http://onto.fel.cvut.cz/ontologies/form/used-only-for-completeness",te.REQUIRES_ANSWER_DESCRIPTION_IF="http://onto.fel.cvut.cz/ontologies/form/requires-answer-description-if",te.REQUIRES_ANSWER_IF="http://onto.fel.cvut.cz/ontologies/form/requires-answer-if",te.HAS_PRECEDING_QUESTION="http://onto.fel.cvut.cz/ontologies/form/has-preceding-question",te.HAS_PRECEDING_VALUE="http://onto.fel.cvut.cz/ontologies/form/has-preceding-value",te.HAS_MEDIA_CONTENT="http://onto.fel.cvut.cz/ontologies/form/has-media-content",te.ASSET="http://onto.fel.cvut.cz/ontologies/form/media/asset",te.HAS_SOURCE="http://onto.fel.cvut.cz/ontologies/form/media/has-source",te.HAS_ANNOTATION="http://onto.fel.cvut.cz/ontologies/form/media/has-annotation",te.CONDITION="http://onto.fel.cvut.cz/ontologies/form/condition",te.OR_CONDITION="http://onto.fel.cvut.cz/ontologies/form/or-condition",te.HAS_SUB_CONDITION="http://onto.fel.cvut.cz/ontologies/form/has-sub-condition",te.HAS_PATTERN="http://onto.fel.cvut.cz/ontologies/form-lt/has-pattern",te.HAS_DECLARED_PREFIX="http://onto.fel.cvut.cz/ontologies/form-spin/has-declared-prefix",te.PREFIX="http://www.w3.org/ns/shacl#prefix",te.NAMESPACE="http://www.w3.org/ns/shacl#namespace",te.HAS_COMMENT="http://onto.fel.cvut.cz/ontologies/form/has-comment",te.HAS_COMMENT_VALUE="http://onto.fel.cvut.cz/ontologies/form/has-comment-value",te.HAS_AUTHOR="http://onto.fel.cvut.cz/ontologies/form/has-author",te.HAS_TIMESTAMP="http://onto.fel.cvut.cz/ontologies/form/has-timestamp",te.TIME_FORMAT="http://onto.fel.cvut.cz/ontologies/form/time-format",te.DATE_FORMAT="http://onto.fel.cvut.cz/ontologies/form/date-format",te.DATETIME_FORMAT="http://onto.fel.cvut.cz/ontologies/form/datetime-format",te.TIMESTAMP_FORMAT="http://onto.fel.cvut.cz/ontologies/form/timestamp-format",te.NOT_ANSWERED_QUESTION="http://onto.fel.cvut.cz/ontologies/form/not-answered-question",te.ANSWERED_QUESTION="http://onto.fel.cvut.cz/ontologies/form/answered-question",te.HAS_VALIDATION_SEVERITY="http://onto.fel.cvut.cz/ontologies/form/has-validation-severity",te.RDFS_LABEL=c.RDFS_LABEL,te.RDFS_COMMENT=c.RDFS_COMMENT,te.DEFAULT_HAS_CHILD=c.DEFAULT_HAS_CHILD,te.BROADER="http://www.w3.org/2004/02/skos/core#broader",te.HAS_NON_SELECTABLE_VALUE="http://onto.fel.cvut.cz/ontologies/form/has-non-selectable-value",te.PROVIDES_DEREFERENCEABLE_ANSWER_VALUES="http://onto.fel.cvut.cz/ontologies/form/provides-dereferenceable-answer-values",te.ICONS={QUESTION_COMMENTS:"questionComments",QUESTION_HELP:"questionHelp",QUESTION_LINK:"questionLink",QUESTION_HINT:"questionHint"},te.ICON_BEHAVIOR={ENABLE:"enable",DISABLE:"disable",ON_HOVER:"onHover"},te.DEFAULT_OPTIONS={icons:[{id:ee.ICONS.QUESTION_HELP,behavior:ee.ICON_BEHAVIOR.ENABLE},{id:ee.ICONS.QUESTION_COMMENTS,behavior:ee.ICON_BEHAVIOR.ON_HOVER},{id:ee.ICONS.QUESTION_LINK,behavior:ee.ICON_BEHAVIOR.ON_HOVER},{id:ee.ICONS.QUESTION_HINT,behavior:ee.ICON_BEHAVIOR.DISABLE}],enableOptionQuestionFeedback:!1},te.ANNOTATION={HAS_ANNOTATION_TYPE:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-annotation-type",HAS_START_TIME:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-start-time",HAS_END_TIME:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-end-time",HAS_GEOMETRY_POINTS:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-geometry-points",HAS_OPACITY:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-opacity",HAS_COLOR:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-color"},te.POLYLINE_ANNOTATION={IMPLICIT_TYPE_LABEL:"polyline",HAS_STROKE_WIDTH:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-stroke-width",HAS_FILL_COLOR:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-fill-color",DEFAULT_POLYLINE_ANNOTATION_STYLE:{color:"red",strokeWidth:2e-6,fillColor:"transparent",opacity:1}},te.TEXT_ANNOTATION={IMPLICIT_TYPE_LABEL:"text",HAS_FONT_SIZE:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-font-size",HAS_FONT_WEIGHT:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-font-weight",HAS_TEXT:"http://onto.fel.cvut.cz/ontologies/form/media/annotation/has-text",DEFAULT_TEXT_ANNOTATION_STYLE:{text:"Hello world",color:"red",fontSizeInNormalizedPx:.05,fontWeight:"300",fontFamily:"sans-serif",fontColor:"red",opacity:1}},te.LANG={cs:{locale:"cs",label:"Čestina"},en:{locale:"en",label:"English"}},te.VALIDATION={SEVERITY:{ERROR:"error",WARNING:"warning"},DEFAULT_MESSAGE:{REQUIRED:"This field is required.",REQUIRED_ONLY_FOR_COMPLETENESS:"This field is required to complete the form.",INVALID:"This field is invalid.",CHECK:"This field must be checked.",LOWER_OR_EQUAL:"This field should be a number equal or lower to ",GREATER_OR_EQUAL:"This field must be greater or equal to "},CLASSNAME:{ERROR:"is-invalid",WARNING:"is-warning"}};var ne={"comment.form.placeholder":"Sem napište své komentáře (Ctrl+Enter pro potvrzení)","wizard.nav.tooltip":"Navigace na této kartě je zakázána, aby nedošlo k přehlédnutí důležitých otázek. K navigaci na tuto kartu použijte tlačítka související s formulářem.","wizard.next":"Další","wizard.previous":"Předchozí","section.expand":"Rozbalit","section.collapse":"Sbalit","validation.required":"Toto pole je povinné.","validation.required_only_for_completeness":"Toto pole je povinné pro vyplnění formuláře.","validation.invalid":"Toto pole je neplatné.","validation.check":"Toto pole musí být zkontrolováno.","validation.lower_or_equal":"Toto pole by mělo být číslo rovné nebo nižší než ","validation.greater_or_equal":"Toto pole musí být větší nebo rovno ","error.default_message":"Něco se pokazilo.","error.view_details":"Zobrazit podrobnosti o chybě","comment.unknownAuthor":"Neznámý autor"},oe={"comment.form.placeholder":"Write your comments here (Ctrl+Enter to confirm, Esc to cancel)","wizard.nav.tooltip":"Navigation to this tab is disabled to prevent overlooking important questions. Use form-related buttons to navigate to this tab instead.","wizard.next":"Next","wizard.previous":"Previous","section.expand":"Expand","section.collapse":"Collapse","validation.required":"This field is required.","validation.required_only_for_completeness":"This field is required to complete the form.","validation.invalid":"This field is invalid.","validation.check":"This field must be checked.","validation.lower_or_equal":"This field should be a number equal or lower to ","validation.greater_or_equal":"This field must be greater or equal to ","error.default_message":"Something went wrong.","error.view_details":"View Error Details","comment.unknownAuthor":"Unknown Author"};const se=/*#__PURE__*/e.createContext({}),re=({children:t,locale:n=navigator.language})=>{let o=oe;return n===te.LANG.cs.locale&&(o=ne),/*#__PURE__*/e.createElement(se.Provider,{value:{locale:n,lang:o}},/*#__PURE__*/e.createElement(u,{locale:n,messages:o},t))};var ie,ae={"@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":""}}]}]}]};class le{static generateForm(){return JSON.parse(JSON.stringify(ae))}}class ce{static getStringHash(e){let t=0;const n=e?e.length:0;if(0===n)return t;for(let o=0;o<n;o++)t=(t<<5)-t+e.charCodeAt(o),t&=t;return t}static asArray(e){return e?e.constructor===Array?e:[e]:[]}static findQuestionById(e,t,n,o,s){if(n&&t["@id"]===e)return t;const r=ce.asArray(t[te.HAS_SUBQUESTION]);if(o)for(let t of r){let n=ce.findQuestionById(e,t,!0,!1,!1);if(n)return n}if(s)for(let t of r){let n=ce.findQuestionById(e,t,!1,!0,!0);if(n)return n}return null}static findKeyInObjects(e,t){for(let n=0;n<e.length;n++)for(let o=0;o<t.length;o++)if(e[n].hasOwnProperty(t[o]))return t[o];return null}static isOptionQuestionFeedbackEnabled(e){var t;return null!=(t=null==e?void 0:e.enableOptionQuestionFeedback)&&t}}class ue{static putObject(e,t){ue.objectMap[e]=t}static getObject(e){return ue.objectMap[e]}}ue.objectMap={};class de{static getFirstObject(e,t){const n=m.getValues(e,t);return 0===n.length?null:n[0]}static compareValues(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"])))||m.compareValues(e,t)}static toplogicalSort(e,t){let n;do{n=!1;for(let o=0;o<e.length;o++)for(let s=o;s<e.length;s++)if(e[o][t]&&("object"==typeof e[o][t]?e[o][t]["@id"]:e[o][t])===e[s]["@id"]){const t=e[o];e[o]=e[s],e[s]=t,n=!0;break}}while(n);return e}static orderPreservingToplogicalSort(e,t){const n=p(),o={};for(let s=0;s<e.length;s++){let r=e[s]["@id"];n.add(r),o[r]=e[s],ce.asArray(e[s][t]).map(e=>"object"==typeof e?e["@id"]:e).map(e=>[e,r]).forEach(e=>n.add(e))}let s=n.sort();for(let t=0;t<s.length;t++)e[t]=o[s[t]];return e}static getCompareLocalizedLabelFunction(e){return(t,n)=>{const o=c.getLocalized(t[c.RDFS_LABEL],e),s=c.getLocalized(n[c.RDFS_LABEL],e);return o<s?-1:o>s?1:0}}static orderByLocalizedLabels(e,t){return e.sort(de.getCompareLocalizedLabelFunction(t))}static checkId(e,t){if(void 0!==e)return e.constructor===Array?!!e.find(e=>e["@id"]===t):e.constructor===Object?e["@id"]===t:void 0}}class me{static isForm(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.FORM)}static isWizardStep(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.WIZARD_STEP)}static isSection(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.QUESTION_SECTION)}static isAnswerable(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.ANSWERABLE)}static isTypeahead(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.QUESTION_TYPEAHEAD)}static getPossibleValuesQuery(e){return c.getJsonAttValue(e,te.HAS_OPTIONS_QUERY)}static isDisabled(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.DISABLED)}static isHidden(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.HIDDEN)}static isTextarea(e,t){return t&&t.length>te.INPUT_LENGTH_THRESHOLD&&!me.isTypeahead(e)||c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.TEXTAREA)}static isText(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.TEXT)}static isCalendar(e){return me.isDate(e)||me.isTime(e)||me.isDateTime(e)}static isDate(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.DATE)}static isTime(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.TIME)}static isDateTime(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.DATETIME)}static isTimestamp(e){return c.hasValue(e,te.TIMESTAMP_FORMAT,te.EPOCH_MILLISECONDS)}static isCheckbox(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.CHECKBOX)}static isMaskedInput(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.MASKED_INPUT)}static isSparqlInput(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.SPARQL)}static isTurtleInput(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.TURTLE)}static isCollapsed(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.COLLAPSED)}static isEmphasised(e){return c.hasValue(e,te.LAYOUT_CLASS,te.LAYOUT.EMPHASISED)}static getCategory(e){return te.LAYOUT.CATEGORY.find(t=>c.hasValue(e,te.LAYOUT_CLASS,t))}static resolveValue(e){return e?e[te.HAS_OBJECT_VALUE]?e[te.HAS_OBJECT_VALUE]["@id"]:c.getJsonAttValue(e,te.HAS_DATA_VALUE):null}static resolveValueObject(e){return e?e[te.HAS_OBJECT_VALUE]?ce.asArray(e[te.HAS_OBJECT_VALUE])[0]:e[te.HAS_DATA_VALUE]?ce.asArray(e[te.HAS_DATA_VALUE])[0]:null:null}static isRelevant(e){if(!e[te.IS_RELEVANT_IF])return!0;for(let t of ce.asArray(e[te.IS_RELEVANT_IF]))if(!me.testCondition(t))return!1;return!0}static hasValidationLogic(e){return!!(e[te.REQUIRES_ANSWER]||e[te.REQUIRES_ANSWER_IF]||e[te.PATTERN]||this.containsXSDProperty(e))}static isValid(e){if(!1===e[te.HAS_VALID_ANSWER])return!1;for(const t of ce.asArray(e[te.HAS_SUBQUESTION]))if(!1===this.isValid(t))return!1;return!0}static testOrCondition(e){const t=e[te.HAS_SUB_CONDITION];t||console.warn("Or condition does not have any sub-condition !");for(const e of this._getMappedObjectsArray(t))if(this.testCondition(e))return!0;return!1}static testCondition(e){const t=e[te.ACCEPTS_VALIDATION_VALUE],n=e[te.ACCEPTS_ANSWER_VALUE],o=e[te.ACCEPTS],s=e[te.HAS_TESTED_QUESTION];let r;if(e[te.HAS_SUB_CONDITION])return this.testOrCondition(e);if(t&&n&&console.warn("Support for validation and requirement constraints at same time is not implemented !"),o&&s){const e=ce.asArray(o);if(1!==e.length&&console.warn("Support for multiple accepts values is not implemented !"),e[0]["@id"]===te.ANSWERED_QUESTION){(n||t)&&console.warn("Support for accepted answer/validations values is not implemented !");for(const e of this._getMappedObjectsArray(s))if(!this.hasAnswer(e))return!1;return!0}console.warn("No support to accept question of type "+e[0]["@id"]+" !")}if(t&&s){const e=ce.asArray(t);(1!==e.length||!0!==e[0]&&"true"!==e[0])&&console.warn('Validation values other than "true" are not implemented !');for(const e of ce.asArray(s)){if(r=ue.getObject(e["@id"]),void 0===r)return console.warn("Questions is not loaded in an object map."),!0;if(!1===this.isValid(r))return!1}return!0}if(n&&s){r=ue.getObject(s["@id"]);for(const e of ce.asArray(n)){if(!r)return console.warn("Question is not defined."),!0;if(!r.hasOwnProperty(te.HAS_ANSWER))return!1;const t=m.getValues(r,te.HAS_ANSWER);if(0===t.length)return!1;const n=me.resolveValueObject(t[0]);if(n&&e&&n.hasOwnProperty("@value")&&e.hasOwnProperty("@id")&&n["@value"]==e["@id"])return!0;if(de.compareValues(n,e))return!0}}return!1}static _getMappedObjectsArray(e,t){return ce.asArray(e).map(e=>{const n=ue.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})}static hasAnswer(e){if(!e)return!1;if(e.hasOwnProperty(te.HAS_ANSWER)){const t=m.getValues(e,te.HAS_ANSWER);if(t.length){const e=me.resolveValueObject(t[0]);if(e&&(e["@value"]||e["@id"]))return!0}}for(const t of ce.asArray(e[te.HAS_SUBQUESTION]))if(me.hasAnswer(t))return!0;return!1}static hasCorrectAnswer(e){if(!e)return!1;if(e.hasOwnProperty(te.HAS_CORRECT_ANSWER)){let t=m.getValues(e,te.HAS_CORRECT_ANSWER);if(Array.isArray(t)&&0!==t.length){t=t[0];const e=me.resolveValueObject(t);if(e&&(e["@value"]||e["@id"]))return!0}return!(!t["@value"]&&!t["@id"])}for(const t of ce.asArray(e[te.HAS_SUBQUESTION]))if(me.hasCorrectAnswer(t))return!0;return!1}static getAnswerValue(e){if(!e)return null;if(e.hasOwnProperty(te.HAS_ANSWER)){const t=m.getValues(e,te.HAS_ANSWER);if(t.length){const e=me.resolveValueObject(t[0]);if(e&&(e["@value"]||e["@id"]))return e["@value"]||e["@id"]}}for(const t of ce.asArray(e[te.HAS_SUBQUESTION])){const e=me.getAnswerValue(t);if(e)return e}return null}static getCorrectAnswerValue(e){if(!e)return null;if(e.hasOwnProperty(te.HAS_CORRECT_ANSWER)){var t,n;let r=m.getValues(e,te.HAS_CORRECT_ANSWER);if(!r)return null;Array.isArray(r)&&(r=r[0]);let i=m.getValues(r,te.HAS_DATA_VALUE)||m.getValues(r,te.HAS_OBJECT_VALUE);if(i&&(!Array.isArray(i)||i.length>0)){var o;Array.isArray(i)&&(i=i[0]);const e=i[te.RDFS_LABEL];var s;return e?null!=(s=e["@value"])?s:e:null!=(o=i["@value"])?o:null}return null!=(t=null!=(n=r["@value"])?n:r[te.RDFS_LABEL])?t:null}for(const t of ce.asArray(e[te.HAS_SUBQUESTION])){const e=me.getCorrectAnswerValue(t);if(e)return e}return null}static resolveDateTimeFormat(e,t,n){const o=me.isDate(e),s=me.isTime(e),r=me.isDateTime(e);switch(!0){case o:return e[te.DATE_FORMAT]||n.dateFormat;case s:return e[te.TIME_FORMAT]||n.timeFormat;case r:return e[te.DATETIME_FORMAT]||n.dateTimeFormat;default:return null}}static dfsTraverseQuestionTree(e,t,n=(()=>{})){function o(e){t(e),ce.asArray(e[te.HAS_SUBQUESTION]).forEach(e=>{o(e)}),n(e)}e.forEach(e=>{o(e)})}static getFormSpecification(e){let t=-1;const n="..";let o="";return me.dfsTraverseQuestionTree(e,function(e){t+=1;const s=" ".repeat(t);let r="";e[te.REQUIRES_ANSWER]&&!e[te.USED_ONLY_FOR_COMPLETENESS]?r=s+n+"required: "+e[te.REQUIRES_ANSWER]+"\n":e[te.USED_ONLY_FOR_COMPLETENESS]&&(r=s+n+"required only for completeness: "+e[te.USED_ONLY_FOR_COMPLETENESS]+"\n"),o+=s+e["http://www.w3.org/2000/01/rdf-schema#label"]+"\n",o+=e[te.HELP_DESCRIPTION]?s+n+"description: "+e[te.HELP_DESCRIPTION]+"\n":"",o+=r,o+=e[te.PATTERN]?s+n+"pattern: "+e[te.PATTERN]+"\n":"",o+=e[te.INPUT_MASK]?s+n+"mask: "+e[te.INPUT_MASK]+"\n":"",o+=e[te.XSD.MAX_INCLUSIVE]?s+n+"This field should be a number equal or lower to "+e[te.XSD.MAX_INCLUSIVE]+"\n":"",o+=e[te.XSD.MIN_INCLUSIVE]?s+n+"This field must be greater or equal to "+e[te.XSD.MIN_INCLUSIVE]+"\n":"",o+=e[te.HAS_VALIDATION_MESSAGE]?s+n+"validation-message: "+e[te.HAS_VALIDATION_MESSAGE]+"\n":"",o+="\n"},function(){t-=1}),o}static containsXSDProperty(e){const t=Object.keys(e),n=Object.values(te.XSD);for(const e of n)if(t.includes(e))return!0;return!1}static getInputMask(e){if(e[te.INPUT_MASK])return e[te.INPUT_MASK]}static hasMediaContentWithAnnotations(e){if(e[te.HAS_MEDIA_CONTENT])for(const t of ce.asArray(e[te.HAS_MEDIA_CONTENT]))if(t[te.HAS_ANNOTATION]&&ce.asArray(t[te.HAS_ANNOTATION]).length>0)return!0;return!1}static containsHints(e){if(e[te.HAS_SUBQUESTION])for(const t of ce.asArray(e[te.HAS_SUBQUESTION]))if(me.containsHints(t))return!0;return this.hasCorrectAnswer(e)||this.hasMediaContentWithAnnotations(e)}}class pe{static log(e){console.log(e)}static warn(e){console.warn?console.warn(e):console.log("WARNING: "+e)}static error(e){console.error?console.error(e):console.log("ERROR: "+e)}}const he={root:{[te.HAS_LAYOUT_CLASS]:te.FORM},expandProperties:[te.HAS_SUBQUESTION,te.IS_RELEVANT_IF,te.HAS_ANSWER,te.HAS_DECLARED_PREFIX,te.HAS_OPTION,te.HAS_CORRECT_ANSWER,te.HAS_COMMENT,te.HAS_MEDIA_CONTENT,te.HAS_ANNOTATION]};class Ee{static customFrame(e,t,n){if(arguments.length<2)return m.nextTick(function(){n(new TypeError("Could not frame, too few arguments."))});null===t&&(t=he),m.flatten(e,null,null,(e,t)=>{})}static expandStructure(e){let t;const n={};e["@graph"].forEach(e=>{n[e["@id"]]=e,me.isForm(e)&&(t=e)});try{this._expandGraph(t,he,n)}catch(e){console.error("Error '"+e+"' occured, while trying to apply frame-ing with custom shape.")}return n}static _expandGraph(e,t,n){let o,s,r;t.expandProperties.forEach(i=>{if(e.hasOwnProperty(i)){e[i]=ce.asArray(e[i]),o=e[i];for(let e=0;e<o.length;e++)r=this._getId(o[e]),s=n[r],void 0!==s?(o[e]=s,this._expandGraph(s,t,n)):console.warn("object with @id "+r+" was not defined in input data.")}})}static _getId(e){return"string"==typeof e?e:e&&"object"==typeof e?e["@id"]:void 0}}ie=Ee,Ee.compressStructure=e=>{let t=[],n=new Set;return t=ie._compressGraph(e,t,n),t=t.sort((e,t)=>e["@id"]&&t["@id"]?e["@id"].localeCompare(t["@id"]):0),t},Ee._compressGraph=(e,t,n)=>(n.has(e["@id"])||(t.push(e),n.add(e["@id"])),he.expandProperties.forEach(o=>{if(e.hasOwnProperty(o)){const s=e[o];for(let r=0;r<s.length;r++){const i=s[r];void 0!==i&&(s[r]=i,t=ie._compressGraph(i,t,n),e[o][r]={"@id":i["@id"]})}}}),t);class Ae{static constructDefaultForm(e){const t=le.generateForm();return Ae._constructFormQuestions(t,e)}static async constructForm(e,t){let n,o;return m.flatten(e,{}).then(e=>{try{const[s,r]=Ae._constructFormQuestions(e,t);o=r,n={formQuestions:s}}catch(e){console.error("Error while constructing form questions from the provided structure:",e)}if(!o){const[e,s]=Ae.constructDefaultForm(t);o=s,n={formQuestions:e}}return[n,o]}).catch(e=>(console.error("Failed to flatten the JSON-LD structure. Expected to transform a nested JSON-LD document into a flattened array of node objects:",e),[n,o]))}static _constructFormQuestions(e,t){let n,o,s,r=[];if(void 0!==e["@graph"][0]["@id"]?(s=Ee.expandStructure(e),Object.keys(s).map(e=>{ue.putObject(e,s[e])})):console.warn("default form is constructed."),n=e["@graph"].find(e=>me.isForm(e)),o=n[te.HAS_SUBQUESTION],!o)throw pe.error("Could not find any questions in the received data."),"No questions in the form";return r=o.filter(e=>!(!me.isWizardStep(e)||me.isHidden(e))||(pe.warn("Item is not a wizard step: "+e),!1)),r.length||(pe.log("Could not find any wizard steps in the received data. Building form without steps"),n[te.HAS_SUBQUESTION].forEach(e=>r.push(e))),r.sort(de.getCompareLocalizedLabelFunction(t)),de.orderPreservingToplogicalSort(r,te.HAS_PRECEDING_QUESTION),[r,{root:n}]}}const ge=["validation","children","value"];class Se extends e.Component{constructor(e){super(e),this.state={cursorPosition:0}}focus(){x.findDOMNode(this.input).focus()}getInputDOMNode(){return x.findDOMNode(this.input)}componentDidUpdate(e,t,n){(this.fieldDidShrink(e)||this.fieldDidExpand(e))&&this.updateFieldCursorPosition()}fieldDidExpand(e){return"textarea"===this.props.type&&"textarea"!==e.type}fieldDidShrink(e){return"text"===this.props.type&&"text"!==e.type}updateFieldCursorPosition(){this.focus(),this.getInputDOMNode().setSelectionRange(this.state.cursorPosition,this.state.cursorPosition)}saveCursorPosition(e){this.props.onChange(e),this.setState({cursorPosition:e.target.selectionStart})}render(){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()}}_renderCheckbox(){/*#__PURE__*/return e.createElement(h.Group,{size:"small",controlId:Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),className:"mb-3"},/*#__PURE__*/e.createElement(h.Check,$({type:"checkbox",ref:e=>this.input=e},this.props,{label:this.props.label,className:this.props.validation.classname})),this.props.validation.message)}_renderRadio(){/*#__PURE__*/return e.createElement(E,{size:"small",className:"mb-3"},/*#__PURE__*/e.createElement(h.Check,$({type:"radio",ref:e=>this.input=e},this.props,{label:this.props.label,className:this.props.validation.classname})),this.props.validation.message)}_renderSelect(){const t=this.props,{validation:n,children:o,value:s}=t,r=Z(t,ge);/*#__PURE__*/return e.createElement(E,{size:"small",className:"mb-3"},this._renderLabel(),/*#__PURE__*/e.createElement(A,$({as:"select",value:s,className:n.classname,ref:e=>this.input=e},r),o),n.message)}_renderLabel(){return this.props.label?/*#__PURE__*/e.createElement(h.Label,null,this.props.label):null}_renderTextArea(){/*#__PURE__*/return e.createElement(E,{size:"small",className:"mb-3"},this._renderLabel(),/*#__PURE__*/e.createElement(A,$({ref:e=>this.input=e,as:"textarea"},this.props,{className:this.props.validation.classname,onChange:e=>this.saveCursorPosition(e)})),this.props.validation.message)}_renderInput(){/*#__PURE__*/return e.createElement(E,{size:"small",className:"mb-3"},this._renderLabel(),/*#__PURE__*/e.createElement(A,$({className:this.props.validation.classname,ref:e=>this.input=e,as:"input",placeholder:this.props.placeholder},this.props,{onChange:e=>this.saveCursorPosition(e)})),this.props.validation.message)}}Se.propTypes={type:U.string,label:U.object,value:U.any,onChange:U.func,help:U.string,validation:U.object,placeholder:U.string},Se.defaultProps={type:"text"};const fe=["children"],ve=/*#__PURE__*/e.createContext({}),_e={components:{inputComponent:Se},componentsOptions:{dateTimeAnswer:{dateFormat:"yyyy-MM-dd",timeFormat:"HH:mm",dateTimeFormat:"yyyy-MM-dd HH:mm:ss"},readOnly:!1},options:{intl:{locale:"en"},modalView:!1,modalProps:{},horizontalWizardNav:!0,wizardStepButtons:!0,enableWizardStepSkip:!0,startingStep:0,enableOptionQuestionFeedback:!1}},Te=n=>{let{children:o}=n,s=Z(n,fe);const r=t(()=>({inputComponent:s.components&&s.components.inputComponent||_e.components.inputComponent,componentsOptions:Object.assign({},_e.componentsOptions,s.componentsOptions),options:Object.assign({},_e.options,s.options),mapComponent:s.mapComponent}),[s]);/*#__PURE__*/return e.createElement(ve.Provider,{value:r},o)};Te.propTypes={children:U.element.isRequired,components:U.object,mapComponent:U.func,options:U.object};class Ne extends e.Component{constructor(e){super(e),this.state={hasError:!1,errorLabel:null,errorDetails:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){this.setState({errorLabel:e,errorDetails:t})}render(){if(this.state.hasError){const{lang:t}=this.context;/*#__PURE__*/return e.createElement("div",{style:{padding:"20px"}},/*#__PURE__*/e.createElement(g,{variant:"danger"},/*#__PURE__*/e.createElement(g.Heading,null,t["error.default_message"]||"Something went wrong."),/*#__PURE__*/e.createElement("p",null,this.state.errorLabel&&this.state.errorLabel.toString())),/*#__PURE__*/e.createElement(S,null,/*#__PURE__*/e.createElement(f,null,/*#__PURE__*/e.createElement(f.Header,null,/*#__PURE__*/e.createElement(S,{as:v,variant:"link",eventKey:"0"},t["error.view_details"]||"View Error Details")),/*#__PURE__*/e.createElement(S.Collapse,{eventKey:"0"},/*#__PURE__*/e.createElement(f.Body,null,/*#__PURE__*/e.createElement("pre",{style:{whiteSpace:"pre-wrap"}},this.state.errorDetails&&this.state.errorDetails.componentStack))))))}return this.props.children}}Ne.contextType=se;const Oe=["children"],Ie=/*#__PURE__*/e.createContext({}),Ce=n=>{let{children:o}=n,s=Z(n,Oe),r=[];const i=async(e,t)=>{const n=r[e];if(n&&n.length)return n;const o=await s.fetchTypeAheadValues(t);return o.length?m.frame(o,{},{}).then(t=>{const n=t["@graph"];return r.push(Object.assign({},n,{[e]:n})),n}):(pe.warn(`No data received when loading options using id ${e}`),[])},a=e=>r[e]||[],l=t(()=>({loadFormOptions:i,getOptions:a}),[i,a]);/*#__PURE__*/return e.createElement(Ie.Provider,$({value:l},s),o)};Ce.propTypes={children:U.element.isRequired,fetchTypeAheadValues:U.func};const be={},Re=[],Le=/*#__PURE__*/e.createContext({}),ye=s=>{const[r,i]=n(s.data||be),[a,l]=n(s.formQuestions||Re);o(()=>{if(s.isFormValid){const e=me.isValid(r);s.isFormValid(e)}},[]),o(()=>{i(s.data||be)},[a]);const c=e=>{e&&i(Object.assign({},r,e))},u=(e,t)=>{if(!(!t||e<0||e>=a.length)){if("object"==typeof t){const n=[...a];n[e]=Object.assign({},n[e],t),l(n)}if(Array.isArray(t)&&l(t),s.isFormValid){const e=me.isValid(r);s.isFormValid(e)}}},d=()=>r,m=e=>null==e?a:a[e],p=t(()=>({updateData:c,updateFormQuestionsData:u,getData:d,getFormQuestionsData:m}),[m,d]);/*#__PURE__*/return e.createElement(Le.Provider,$({value:p},s),s.children)};ye.propTypes={children:U.element.isRequired,data:U.object.isRequired,formQuestions:U.array.isRequired,isFormValid:U.func};class we{static buildQuestionAnswerModel(e,t){const n={subQuestions:[]};let o;if(e&&(n.uri=e.root["@id"],n.origin=c.getJsonAttValue(e.root,te.HAS_QUESTION_ORIGIN,"@id")),t)for(let e=0;e<t.length;e++)o=we.processQuestionAnswerHierarchy(t[e]),o&&n.subQuestions.push(o);return n}static processQuestionAnswerHierarchy(e){return e?we._processQuestion(e):null}static _processQuestion(e){const t={};if(t.uri=e["@id"],t.origin=c.getJsonAttValue(e,te.HAS_QUESTION_ORIGIN,"@id"),e[te.HAS_SUBQUESTION]){t.subQuestions=[];for(let n=0;n<e[te.HAS_SUBQUESTION].length;n++)t.subQuestions.push(we._processQuestion(e[te.HAS_SUBQUESTION][n]))}if(e[te.HAS_ANSWER]){t.answers=[],Array.isArray(e[te.HAS_ANSWER])||(e[te.HAS_ANSWER]=[e[te.HAS_ANSWER]]);for(let n=0;n<e[te.HAS_ANSWER].length;n++)t.answers.push(we.processAnswer(e[te.HAS_ANSWER][n]))}if(e[te.HAS_COMMENT]){t.comments=[],Array.isArray(e[te.HAS_COMMENT])||(e[te.HAS_COMMENT]=[e[te.HAS_COMMENT]]);for(let n=0;n<e[te.HAS_COMMENT].length;n++)t.comments.push(we.processComment(e[te.HAS_COMMENT][n]))}return t}static processComment(e){const t={};return t.author=c.getJsonAttValue(e,te.HAS_AUTHOR,"@id"),t.value=c.getJsonAttValue(e,te.HAS_COMMENT_VALUE),t.timestamp=c.getJsonAttValue(e,te.HAS_TIMESTAMP,"@id"),t}static processAnswer(e){const t={};return t.uri=e["@id"],t.origin=c.getJsonAttValue(e,te.HAS_ANSWER_ORIGIN,"@id"),e[te.HAS_OBJECT_VALUE]?t.codeValue=c.getJsonAttValue(e,te.HAS_OBJECT_VALUE,"@id"):t.textValue=c.getJsonAttValue(e,te.HAS_DATA_VALUE),t}static generateAnswer(e){const t={};return t[te.HAS_DATA_VALUE]="",t}}const He=t=>{const{inputComponent:n,componentsOptions:o}=s(ve);/*#__PURE__*/return e.createElement(n,{type:"checkbox",label:t.label,title:t.title,checked:!0===t.value||"true"===t.value,validation:t.validation,onChange:e=>{t.onChange(e.target.checked)},disabled:o.readOnly||me.isDisabled(t.question)})};He.propTypes={question:U.object.isRequired,label:U.object.isRequired,title:U.string,value:U.oneOfType([U.string,U.bool]),onChange:U.func.isRequired,mouseHover:U.bool,validation:U.object};const De=t=>{const{componentsOptions:r}=s(ve),[i,a]=n(null),[l,c]=n(""),u=me.resolveDateTimeFormat(t.question,t.value,r.dateTimeAnswer),d=me.isDate(t.question),m=me.isTime(t.question),p=me.isTimestamp(t.question);o(()=>{const e=A(t.value);e?a(e):(a(null),c(`Invalid date value ${t.value} of question ${t.question["@id"]}.`),console.error(l))},[t.value,u]);const A=e=>{if(!e)return null;const t=p?new Date(e):q(e,u,new Date);return isNaN(t.getTime())?null:t};/*#__PURE__*/return e.createElement(E,{size:"small",className:"mb-3"},/*#__PURE__*/e.createElement(h.Label,{className:"w-100"},t.label),/*#__PURE__*/e.createElement(P,{selected:i,placeholderText:u,onChange:e=>{a(e);const n=e?p?e.getTime():k(e,u):"";t.onChange(n)},showTimeSelect:!d,showTimeSelectOnly:m,timeFormat:"HH:mm",timeIntervals:1,timeCaption:"Time",dateFormat:u,className:F("form-control",t.validation.classname),disabled:r.readOnly||me.isDisabled(t.question)}),t.validation.message)};De.propTypes={question:U.object.isRequired,label:U.object.isRequired,title:U.string,value:U.oneOfType([U.string,U.number]),onChange:U.func.isRequired,validation:U.object};const Ve=[te.XSD.INT,te.XSD.INTEGER,te.XSD.NON_NEGATIVE_INTEGER,te.XSD.NON_POSITIVE_INTEGER,te.XSD.NEGATIVE_INTEGER,te.XSD.POSITIVE_INTEGER,te.XSD.FLOAT,te.XSD.POSITIVE_FLOAT,te.XSD.NEGATIVE_FLOAT],Me={};Me[te.XSD.NON_NEGATIVE_INTEGER]={min:0},Me[te.XSD.NON_POSITIVE_INTEGER]={max:0},Me[te.XSD.NEGATIVE_INTEGER]={max:-1},Me[te.XSD.POSITIVE_INTEGER]={min:1};const Ue={"string-2":"prefixed",atom:"var"};class xe{static _resolveInputType(e,t){return me.isSparqlInput(e)||me.isTurtleInput(e)||me.isTextarea(e,t)?"textarea":xe._isNumeric(e)?"number":"text"}static _isNumeric(e){for(let t=0,n=Ve.length;t<n;t++)if(c.hasValue(e,te.HAS_DATATYPE,Ve[t]))return!0;return!1}static resolveInputProperties(e,t,n){let o={};switch(o.type=xe._resolveInputType(e,t),o.type){case"textarea":o.rows=5;break;case"number":o=Object.assign({},o,xe._resolveNumberRestrictions(e),this._resolveStepRestriction(e))}return o.disabled=n.readOnly||me.isDisabled(e),o}static _resolveStepRestriction(e){let t={};return void 0!==e[te.STEP]&&(t.step=c.getJsonAttValue(e,te.STEP)),t}static _resolveNumberRestrictions(e){let t={};return Object.getOwnPropertyNames(Me).forEach(n=>{c.hasValue(e,te.HAS_DATATYPE,n)&&(t=Object.assign({},t,Me[n]))}),void 0!==e[te.XSD.MIN_INCLUSIVE]&&(t.min=e[te.XSD.MIN_INCLUSIVE]),void 0!==e[te.XSD.MIN_EXCLUSIVE]&&(t.min=e[te.XSD.MIN_EXCLUSIVE]+1),void 0!==e[te.XSD.MAX_EXCLUSIVE]&&(t.max=e[te.XSD.MAX_EXCLUSIVE]-1),void 0!==e[te.XSD.MAX_INCLUSIVE]&&(t.max=e[te.XSD.MAX_INCLUSIVE]),t}static _preventCharacterInput(e,t){"number"!==xe._resolveInputType(t)||e.key>="0"&&e.key<="9"||["Backspace","Delete","ArrowLeft","ArrowRight","-","Minus","NumpadSubtract",".","Period"].includes(e.key)||e.preventDefault()}}const Pe=t=>{const{inputComponent:n,componentsOptions:o}=s(ve),r=t.question,i=t.answer;let a=t.value;return i[te.HAS_OBJECT_VALUE]&&i[te.HAS_OBJECT_VALUE][c.RDFS_LABEL]&&(a=c.getJsonAttValue(i[te.HAS_OBJECT_VALUE],c.RDFS_LABEL)),/*#__PURE__*/e.createElement(n,Object.assign({},xe.resolveInputProperties(r,a,o),{validation:t.validation,label:t.label,title:t.title,value:null==a?"":a,placeholder:me.getInputMask(r),onKeyPress:e=>xe._preventCharacterInput(e,r),onChange:e=>{t.onChange(e.target.value),(t.sparql||t.turtle)&&(void 0).hide()},onFocus:e=>{if(t.sparql){const n=z.fromTextArea(e.target);n.setValue(a),n.on("change",()=>{t.onChange(n.getValue())}),z.Autocompleters.prefixes.appendPrefixIfNeeded=function(e,n){if(!e.autocompleters.getTrie(n))return;if(!e.options.autocompleters||-1===e.options.autocompleters.indexOf(n))return;const o=e.getCursor(),s=e.getTokenAt(o);if("prefixed"===Ue[s.type]){const r=s.string.indexOf(":");if(-1!==r){const i=e.getPreviousNonWsToken(o.line,s).string.toUpperCase(),a=e.getTokenAt({line:o.line,ch:s.start});if("PREFIX"!==i&&("ws"===a.type||null==a.type)){const o=s.string.substring(0,r+1);if(null==e.getPrefixesFromQuery()[o.slice(0,-1)])if(t.question[te.HAS_DECLARED_PREFIX]&&t.question[te.HAS_DECLARED_PREFIX].filter(e=>e[te.PREFIX]===o.slice(0,-1)).length){const n=t.question[te.HAS_DECLARED_PREFIX].filter(e=>e[te.PREFIX]===o.slice(0,-1)),s={};s[n[0][te.PREFIX]]=n[0][te.NAMESPACE],e.addPrefixes(s)}else{const t=e.autocompleters.getTrie(n).autoComplete(o);t.length>0&&e.addPrefixes(t[0])}}}}}}else if(t.turtle){console.log("TTL");const n=z.fromTextArea(e.target);n.setValue(a),n.on("change",()=>{t.onChange(n.getValue())})}}}))};Pe.propTypes={question:U.object.isRequired,answer:U.object.isRequired,label:U.object.isRequired,title:U.string,value:U.oneOfType([U.string,U.number]),onChange:U.func.isRequired,validation:U.object};const qe={D:"1",M:"1",Y:"1",h:"1",m:"1",s:"1"};class ke{static mapMask(e){if(!e)return e;let t,n="";for(let o=0,s=e.length;o<s;o++)t=e.charAt(o),n+=qe[t]?qe[t]:t;return n}}const Fe=["size","placeholder"];function ze(e){let t,n,o,s;if(void 0!==e.selectionStart)t=e.selectionStart,n=e.selectionEnd;else try{e.focus(),o=e.createTextRange(),s=o.duplicate(),o.moveToBookmark(document.selection.createRange().getBookmark()),s.setEndPoint("EndToStart",o),t=s.text.length,n=t+o.text.length}catch(e){}return{start:t,end:n}}class je extends e.Component{constructor(e){super(e),this._updatePattern=e=>{this.mask.setPattern(ke.mapMask(e.mask),{value:this.mask.getRawValue(),selection:ze(this.input)})},this._updateMaskSelection=()=>{this.mask.selection=ze(this.input)},this._updateInputSelection=()=>{!function(e,t){let n;try{void 0!==e.selectionStart?(e.focus(),e.setSelectionRange(t.start,t.end)):(e.focus(),n=e.createTextRange(),n.collapse(!0),n.moveStart("character",t.start),n.moveEnd("character",t.end-t.start),n.select())}catch(e){}}(this.input,this.mask.selection)},this._onChange=e=>{const t=this.mask.getValue();if(e.target.value!==t){if(e.target.value.length<t.length){const n=t.length-e.target.value.length;this._updateMaskSelection(),this.mask.selection.end=this.mask.selection.start+n,this.mask.backspace()}const n=this._getDisplayValue();e.target.value=n,n&&this._updateInputSelection()}this.props.onChange&&this.props.onChange(e)},this._onKeyDown=e=>{if(function(e){return e.ctrlKey&&90===e.keyCode}(e))e.preventDefault(),this.mask.undo()&&(e.target.value=this._getDisplayValue(),this._updateInputSelection(),this.props.onChange&&this.props.onChange(e));else if(function(e){return e.ctrlKey&&89===e.keyCode}(e))e.preventDefault(),this.mask.redo()&&(e.target.value=this._getDisplayValue(),this._updateInputSelection(),this.props.onChange&&this.props.onChange(e));else if("Backspace"===e.key&&(e.preventDefault(),this._updateMaskSelection(),this.mask.backspace())){const t=this._getDisplayValue();e.target.value=t,t&&this._updateInputSelection(),this.props.onChange&&this.props.onChange(e)}},this._onKeyPress=e=>{e.metaKey||e.altKey||e.ctrlKey||"Enter"===e.key||(e.preventDefault(),this._updateMaskSelection(),this.mask.input(e.key)&&(e.target.value=this.mask.getValue(),this._updateInputSelection(),this.props.onChange&&this.props.onChange(e)))},this._onPaste=e=>{e.preventDefault(),this._updateMaskSelection(),this.mask.paste(e.clipboardData.getData("Text"))&&(e.target.value=this.mask.getValue(),setTimeout(this._updateInputSelection,0),this.props.onChange&&this.props.onChange(e))},this.mask=new j({pattern:ke.mapMask(e.mask),value:e.value,formatCharacters:e.formatCharacters,placeholderChar:e.placeholderChar||"_"})}componentDidUpdate(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(ke.mapMask(this.props.mask),{value:this.props.value}):this.mask.setPattern(ke.mapMask(this.props.mask),{value:this.mask.getRawValue()}):e.mask!==this.props.mask?this.mask.setPattern(ke.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()}_getDisplayValue(){const e=this.mask.getValue();return e===this.mask.emptyValue?"":e}focus(){this.input.focus()}blur(){this.input.blur()}render(){const t=this.props,{size:n,placeholder:o}=t,s=Z(t,Fe),r=this.mask.pattern.length;/*#__PURE__*/return e.createElement(this.context.inputComponent,Object.assign({},s,{ref:e=>{e&&(this.input=e.input?x.findDOMNode(e.input):e)},maxLength:r,onChange:this._onChange,onKeyDown:this._onKeyDown,onKeyPress:this._onKeyPress,onPaste:this._onPaste,placeholder:o||this.mask.emptyValue,size:n||r,value:this._getDisplayValue(),type:"text"}))}}je.contextType=ve,je.propTypes={mask:U.string.isRequired},je.defaultProps={value:""};const Qe=t=>{const{componentsOptions:n}=s(ve),o=t.question,r=t.value,i=c.getJsonAttValue(o,te.INPUT_MASK);return i?/*#__PURE__*/e.createElement(je,{mask:i,value:r,label:t.label,title:t.title,placeholder:i,onChange:e=>t.onChange(e.target.value),disabled:n.readOnly||me.isDisabled(o),validation:t.validation}):(pe.warn("Input mask not provided. Falling back to regular input."),/*#__PURE__*/e.createElement(Pe,t))};Qe.propTypes={question:U.object.isRequired,answer:U.object.isRequired,label:U.object.isRequired,title:U.string,value:U.oneOfType([U.string,U.number]),onChange:U.func.isRequired,validation:U.object};const Be=(t,n="-- Select --")=>{const o=[...t].sort((e,t)=>{const n=c.getJsonAttValue(e,te.RDFS_LABEL),o=c.getJsonAttValue(t,te.RDFS_LABEL);return n<o?-1:n>o?1:0}).map((t,n)=>{const o=c.getJsonAttValue(t,te.RDFS_LABEL);/*#__PURE__*/return e.createElement("option",{value:o,key:`opt-${n}`},o)});return[/*#__PURE__*/e.createElement("option",{value:"",key:"opt-placeholder",disabled:!0,hidden:!0},n),...o]},We=({question:t,label:n,title:o,value:r,validation:i,onChange:a})=>{const{inputComponent:l,componentsOptions:c}=s(ve);/*#__PURE__*/return e.createElement(l,{type:"select",label:n,value:r,title:o,validation:i,onChange:e=>a(e.target.value),disabled:c.readOnly||me.isDisabled(t)},Be(t[te.HAS_OPTION]))};function Ye({size:t=17,className:n=""}){/*#__PURE__*/return e.createElement("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",className:n,xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true"},/*#__PURE__*/e.createElement("path",{d:"M18 6L6 18M6 6L18 18",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"}))}function Xe({size:t=17,className:n=""}){/*#__PURE__*/return e.createElement("svg",{width:t,height:t,viewBox:"0 0 50 50",className:n,xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true"},/*#__PURE__*/e.createElement("path",{strokeWidth:3,stroke:"currentColor",d:"M 41.9375 8.625 C 41.273438 8.648438 40.664063 9 40.3125 9.5625 L 21.5 38.34375 L 9.3125 27.8125 C 8.789063 27.269531 8.003906 27.066406 7.28125 27.292969 C 6.5625 27.515625 6.027344 28.125 5.902344 28.867188 C 5.777344 29.613281 6.078125 30.363281 6.6875 30.8125 L 20.625 42.875 C 21.0625 43.246094 21.640625 43.410156 22.207031 43.328125 C 22.777344 43.242188 23.28125 42.917969 23.59375 42.4375 L 43.6875 11.75 C 44.117188 11.121094 44.152344 10.308594 43.78125 9.644531 C 43.410156 8.984375 42.695313 8.589844 41.9375 8.625 Z"}))}We.propTypes={question:U.object.isRequired,label:U.object.isRequired,title:U.string,value:U.string,onChange:U.func.isRequired,validation:U.object},Ye.propTypes={size:U.number,className:U.string},Xe.propTypes={size:U.number,className:U.string};const Ge=({status:t})=>"correct"===t?/*#__PURE__*/e.createElement(Xe,{className:"select-feedback-badge correct visible"}):"incorrect"===t?/*#__PURE__*/e.createElement(Ye,{className:"select-feedback-badge incorrect visible"}):null;Ge.displayName="SelectFeedbackBadge",Ge.propTypes={status:U.oneOf(["correct","incorrect",null])};const Ke="select-correct",Je="select-incorrect",$e=({question:t,label:i,title:a,value:l,validation:u,onChange:d,hintRevealed:m})=>{const{inputComponent:p,componentsOptions:h}=s(ve),E=r(null),[A,g]=n(null),[S,f]=n(null!=l?l:""),v=e=>{const n=((e,t)=>t?e.trim()===t.trim()?"correct":"incorrect":null)(e,me.getCorrectAnswerValue(t));var o,s,r,i;n&&(s="correct"===n,(o=null!=(r=null==(i=E.current)?void 0:i.querySelector("select"))?r:null)&&(o.classList.remove(Ke,Je),o.classList.add(s?Ke:Je)),g(n))};o(()=>{var e;if(!me.hasAnswer(t)||!l)return;const n=((e=[],t)=>{const n=((e=[],t)=>{var n;return null!=(n=e.find(e=>e["@id"]===t))?n:null})(e,t);return n?c.getJsonAttValue(n,te.RDFS_LABEL):t})(null!=(e=t[te.HAS_OPTION])?e:[],l);f(n),v(n)},[]);const _=()=>{const e=me.getCorrectAnswerValue(t);e&&(f(e),d(e),v(e))};return o(()=>{m&&_()},[m]),/*#__PURE__*/e.createElement("div",{ref:E,style:{position:"relative"}},/*#__PURE__*/e.createElement(p,{type:"select",label:i,value:S,title:a,validation:u,onChange:e=>{if(m)return void _();const t=e.target.value;f(t),d(t),v(t)},disabled:h.readOnly||me.isDisabled(t)},Be(t[te.HAS_OPTION])),/*#__PURE__*/e.createElement(Ge,{status:A}))};$e.propTypes={question:U.object.isRequired,label:U.object.isRequired,title:U.string,value:U.string,onChange:U.func.isRequired,validation:U.object,hintRevealed:U.bool};const Ze=t=>{const n=s(ve),o=ce.isOptionQuestionFeedbackEnabled(null==n?void 0:n.options);/*#__PURE__*/return e.createElement(o?$e:We,t)};Ze.propTypes={question:U.object.isRequired,label:U.object.isRequired,title:U.string,value:U.string,onChange:U.func.isRequired,validation:U.object,hintRevealed:U.bool,onRevealHint:U.func};const et=(e,t)=>{if(!e)return[];e=((e,t)=>void 0!==e&&e.length?(e.sort(de.getCompareLocalizedLabelFunction(t)),de.orderPreservingTop