From 964564b766fa1af1ba460dd094e984f2d64e89d3 Mon Sep 17 00:00:00 2001 From: Bharat Chauhan Date: Fri, 24 Mar 2023 18:53:04 +0530 Subject: [PATCH] Bump version to 2.7.1 and update dist files --- dist/react-json-form.cjs | 40 +++++++++++++++++++++++++++------- dist/react-json-form.js | 2 +- dist/react-json-form.modern.js | 40 +++++++++++++++++++++++++++------- dist/react-json-form.module.js | 40 +++++++++++++++++++++++++++------- package.json | 2 +- 5 files changed, 98 insertions(+), 26 deletions(-) diff --git a/dist/react-json-form.cjs b/dist/react-json-form.cjs index 7a30b87..bce07b5 100644 --- a/dist/react-json-form.cjs +++ b/dist/react-json-form.cjs @@ -241,7 +241,7 @@ function getBlankArray(schema, getRef) { let type = normalizeKeyword(schema.items.type); if (!type) { - if (schema.items.hasOwnProperty['oneOf']) type = schema.items.oneOf[0];else if (schema.items.hasOwnProperty['anyOf']) type = schema.items.anyOf[0];else if (schema.items.hasOwnProperty['allOf']) type = schema.items.allOf[0]; + if (Array.isArray(schema.items['oneOf'])) type = getSchemaType(schema.items.oneOf[0]);else if (Array.isArray(schema.items['anyOf'])) type = getSchemaType(schema.items.anyOf[0]);else if (Array.isArray(schema.items['allOf'])) type = getSchemaType(schema.items.allOf[0]); } if (type === 'array') { @@ -251,6 +251,14 @@ function getBlankArray(schema, getRef) { } else if (type === 'object') { while (items.length < minItems) items.push(getBlankObject(schema.items, getRef)); + return items; + } else if (type === 'oneOf') { + while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef)); + + return items; + } else if (type === 'anyOf') { + while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef)); + return items; } @@ -3288,23 +3296,26 @@ function validateArray(schema) { } else { if (!schema.items.hasOwnProperty('oneOf') && !schema.items.hasOwnProperty('anyOf') && !schema.items.hasOwnProperty('allOf')) return { isValid: false, - msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf' or 'allOf'" + msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf'" }; } - if (schema.hasOwnProperty('oneOf')) { + if (schema.items.hasOwnProperty('oneOf')) { validation = validateOneOf(schema.items); if (!validation.isValid) return validation; } - if (schema.hasOwnProperty('anyOf')) { + if (schema.items.hasOwnProperty('anyOf')) { validation = validateAnyOf(schema.items); if (!validation.isValid) return validation; } - if (schema.hasOwnProperty('allOf')) { - validation = validateAllOf(schema.items); - if (!validation.isValid) return validation; + if (schema.items.hasOwnProperty('allOf')) { + // we don't support allOf inside array yet + return { + isValid: false, + msg: "Currently, 'allOf' inside array items is not supported" + }; } return { @@ -3366,13 +3377,18 @@ function validateSubschemas(schema, keyword) { keyword: one of 'oneOf' or 'anyOf' or 'allOf' Validation: 1. Must be an array - 2. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword + 2. Must have at least one subschema + 3. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword */ let subschemas = schema[keyword]; if (!Array.isArray(subschemas)) return { isValid: false, msg: "'" + keyword + "' property must be an array" }; + if (!subschemas.length) return { + isValid: false, + msg: "'" + keyword + "' must contain at least one subschema" + }; for (let i = 0; i < subschemas.length; i++) { let subschema = subschemas[i]; @@ -3758,6 +3774,14 @@ function DataValidator(schema) { let next_validator = this.getValidator(next_type); + if (!next_validator) { + if (next_schema.hasOwnProperty('oneOf')) { + next_validator = this.validateOneOf; + } else if (next_schema.hasOwnProperty('anyOf')) { + next_validator = this.validateAnyOf; + } else if (next_schema.hasOwnProperty('anyOf')) ; + } + if (next_validator) { for (let i = 0; i < data.length; i++) next_validator(next_schema, data[i], this.joinCoords([coords, i])); } else this.addError(coords, 'Unsupported type "' + next_type + '" for array items.'); diff --git a/dist/react-json-form.js b/dist/react-json-form.js index aabfcd4..eff677e 100644 --- a/dist/react-json-form.js +++ b/dist/react-json-form.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-modal"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-modal","react-dom"],t):t((e||self).reactJsonForm={},e.React,e.ReactModal,e.ReactDOM)}(this,function(e,t,a,r){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/n(t),l=/*#__PURE__*/n(a),o=/*#__PURE__*/n(r);function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0||(n[a]=e[a]);return n}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,r=new Array(t);a=a)return e.default;var r=[];if(e.default&&(r=[].concat(e.default)),0===a)return r;e.items.hasOwnProperty("$ref")&&(e.items=t(e.items.$ref));var n=k(e.items.type);if(n||(e.items.hasOwnProperty.oneOf?n=e.items.oneOf[0]:e.items.hasOwnProperty.anyOf?n=e.items.anyOf[0]:e.items.hasOwnProperty.allOf&&(n=e.items.allOf[0])),"array"===n){for(;r.length=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.")}(e);!(a=r()).done;)if(!t.has(a.value))return!1;return!0}(keyset2,keyset1))return!1}else if(r=keyset2,n=keyset1,r.size!==n.size||!Array.from(r).every(function(e){return n.has(e)}))return!1;for(var l in i)if(i.hasOwnProperty(l)){if(!e.hasOwnProperty(l))return!1;var o=k(i[l].type),s=y(e[l]);if("number"===o&&-1===["number","integer","null"].indexOf(s))return!1;if("integer"===o&&-1===["number","integer","null"].indexOf(s))return!1;if("boolean"===o&&-1===["boolean","null"].indexOf(s))return!1;if("string"===o&&"string"!==s)return!1}return!0}function T(e,t){var a=y(e);if(E(t)!==a)return!1;for(var r=t.items.type,n=0;n12?1:"hh"!==e&&t>59?0:t},t.handleChange=function(e){var a,r=e.target.dataset.name,n=e.target.value;if(!isNaN(n)){var i=t.validateValue(r,parseInt(n)||0);"hh"!==r||"0"!==n&&""!==n&&"00"!==n||1!==i||(i=0),n.startsWith("0")&&i<10&&0!==i&&(i=i.toString().padStart(2,"0")),t.sendValue(((a={})[r]=""!==n?i.toString():"",a))}},t.handleKeyDown=function(e){var a;if(38===e.keyCode||40===e.keyCode){var r=e.target.dataset.name,n=parseInt(e.target.value)||0;38===e.keyCode?n++:40===e.keyCode&&n--,t.sendValue(((a={})[r]=t.validateValue(r,n).toString().padStart(2,"0"),a))}},t.handleSpin=function(e,a){var r,n=t.props[e];"ampm"===e?n="am"===n?"pm":"am":(n=parseInt(n)||0,"up"===a?n++:n--,n=t.validateValue(e,n).toString().padStart(2,"0")),t.sendValue(((r={})[e]=n,r))},t.handleBlur=function(e){var a,r=t.validateValue(e.target.dataset.name,parseInt(e.target.value)||0);r<10&&t.sendValue(((a={})[e.target.dataset.name]=r.toString().padStart(2,"0"),a))},t}u(t,e);var a=t.prototype;return a.componentWillUnmount=function(){var e={hh:this.validateValue("hh",this.props.hh).toString().padStart(2,"0"),mm:this.validateValue("mm",this.props.mm).toString().padStart(2,"0"),ss:this.validateValue("ss",this.props.ss).toString().padStart(2,"0")};this.sendValue(e)},a.render=function(){var e=this;/*#__PURE__*/return i.default.createElement("div",{className:"rjf-time-picker"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-row rjf-time-picker-labels"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},"Hrs"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},"Min"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},"Sec"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},"am/pm")),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-row"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(F,{onClick:function(){return e.handleSpin("hh","up")}},/*#__PURE__*/i.default.createElement($,{name:"chevron-up"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(F,{onClick:function(){return e.handleSpin("mm","up")}},/*#__PURE__*/i.default.createElement($,{name:"chevron-up"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(F,{onClick:function(){return e.handleSpin("ss","up")}},/*#__PURE__*/i.default.createElement($,{name:"chevron-up"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(F,{onClick:function(){return e.handleSpin("ampm","up")}},/*#__PURE__*/i.default.createElement($,{name:"chevron-up"})))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-row rjf-time-picker-values"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement("input",{type:"text","data-name":"hh",value:this.props.hh,onChange:this.handleChange,onBlur:this.handleBlur,onKeyDown:this.handleKeyDown})),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"},":"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement("input",{type:"text","data-name":"mm",value:this.props.mm,onChange:this.handleChange,onBlur:this.handleBlur,onKeyDown:this.handleKeyDown})),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"},":"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement("input",{type:"text","data-name":"ss",value:this.props.ss,onChange:this.handleChange,onBlur:this.handleBlur,onKeyDown:this.handleKeyDown})),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},this.props.ampm)),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-row"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(F,{onClick:function(){return e.handleSpin("hh","down")}},/*#__PURE__*/i.default.createElement($,{name:"chevron-down"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(F,{onClick:function(){return e.handleSpin("mm","down")}},/*#__PURE__*/i.default.createElement($,{name:"chevron-down"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(F,{onClick:function(){return e.handleSpin("ss","down")}},/*#__PURE__*/i.default.createElement($,{name:"chevron-down"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(F,{onClick:function(){return e.handleSpin("ampm","down")}},/*#__PURE__*/i.default.createElement($,{name:"chevron-down"})))))},t}(i.default.Component),G=["label","help_text","error","inputRef"],X=["label","help_text","error","value"],Z=["label","help_text","error","value","options"],Q=["label","help_text","error","value","options"],ee=["label","value"],te=["label","help_text","error","inputRef"];function ae(e){return e.label?/*#__PURE__*/i.default.createElement("label",{className:e.required?"rjf-required":null},e.children,e.children&&" ",e.label):null}function re(e){var t=e.label,a=e.help_text,r=e.error,n=e.inputRef,l=c(e,G);return"string"===l.type&&(l.type="text"),n&&(l.ref=n),null===l.value&&(l.value=""),/*#__PURE__*/i.default.createElement("div",null,/*#__PURE__*/i.default.createElement(ae,{label:t,required:l.required}),/*#__PURE__*/i.default.createElement("div",{className:r?"rjf-input-group has-error":"rjf-input-group"},/*#__PURE__*/i.default.createElement("input",l),r&&r.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),a&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},a)))}function ne(e){var t=e.label,a=e.help_text,r=e.error,n=e.value,l=c(e,X);return t||(t=l.name.toUpperCase()),"bool"===l.type&&(l.type="checkbox"),void 0===l.checked&&(l.checked=n),""!==l.checked&&null!=l.checked||(l.checked=!1),l.readOnly&&(l.disabled=!0),/*#__PURE__*/i.default.createElement("div",{className:r?"rjf-check-input has-error":"rjf-check-input"},/*#__PURE__*/i.default.createElement(ae,{label:t,required:l.required},/*#__PURE__*/i.default.createElement("input",l)),r&&r.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),a&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},a))}function ie(e){var t=e.label,a=e.help_text,r=e.error,n=e.value,l=e.options,o=c(e,Z);return o.readOnly&&(o.disabled=!0),/*#__PURE__*/i.default.createElement("div",{className:r?"rjf-check-input has-error":"rjf-check-input"},/*#__PURE__*/i.default.createElement(ae,{label:t,required:o.required}),l.map(function(e,t){var a,r;return"object"==typeof e?(a=e.title||e.label,r=e.value):("boolean"==typeof(a=e)&&(a=v(a.toString())),r=e),/*#__PURE__*/i.default.createElement("label",{key:a+"_"+r+"_"+t},/*#__PURE__*/i.default.createElement("input",s({},o,{value:r,checked:r===n}))," ",a)}),r&&r.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),a&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},a))}function le(e){var t=e.label,a=e.help_text,r=e.error,n=e.value,l=e.options,o=c(e,Q);return o.readOnly&&(o.disabled=!0),n||!1===n||0===n||(n=""),/*#__PURE__*/i.default.createElement("div",null,/*#__PURE__*/i.default.createElement(ae,{label:t,required:o.required}),/*#__PURE__*/i.default.createElement("div",{className:r?"rjf-input-group has-error":"rjf-input-group"},/*#__PURE__*/i.default.createElement("select",s({value:n},o),/*#__PURE__*/i.default.createElement("option",{disabled:!0,value:"",key:"__placehlder"},"Select..."),l.map(function(e,t){var a,r;return"object"==typeof e?(a=e.title||e.label,r=e.value):("boolean"==typeof(a=e)&&(a=v(a.toString())),r=e),/*#__PURE__*/i.default.createElement("option",{value:r,key:a+"_"+r+"_"+t},a)})),r&&r.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),a&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},a)))}var oe=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).handleChange=function(e){var t=[].concat(a.props.value),r=e.target.value;typeof r!==a.props.valueType&&(r=g(r,a.props.valueType)),e.target.checked?t.push(r):t=t.filter(function(e){return e!==r}),a.props.onChange({target:{type:a.props.type,value:t,name:a.props.name}})},a.showOptions=function(e){a.state.showOptions||a.setState({showOptions:!0})},a.hideOptions=function(e){a.setState({showOptions:!1})},a.toggleOptions=function(e){a.setState(function(e){return{showOptions:!e.showOptions}})},a.state={showOptions:!1},a.optionsContainer=/*#__PURE__*/i.default.createRef(),a.input=/*#__PURE__*/i.default.createRef(),a}return u(t,e),t.prototype.render=function(){/*#__PURE__*/return i.default.createElement("div",{className:"rjf-multiselect-field"},/*#__PURE__*/i.default.createElement(re,{label:this.props.label,type:"text",value:this.props.value.length?this.props.value.length+" selected":"Select...",help_text:this.props.help_text,error:this.props.error,onClick:this.toggleOptions,readOnly:!0,inputRef:this.input,className:"rjf-multiselect-field-input"}),this.state.showOptions&&/*#__PURE__*/i.default.createElement(se,{options:this.props.options,value:this.props.value,hideOptions:this.hideOptions,onChange:this.handleChange,containerRef:this.optionsContainer,inputRef:this.input,disabled:this.props.readOnly,hasHelpText:(this.props.help_text||this.props.error)&&1}))},t}(i.default.Component),se=/*#__PURE__*/function(e){function t(){for(var t,a=arguments.length,r=new Array(a),n=0;n-1,o="rjf-multiselect-field-option";return l&&(o+=" selected"),e.props.disabled&&(o+=" disabled"),/*#__PURE__*/i.default.createElement("div",{key:r+"_"+n+"_"+a,className:o},/*#__PURE__*/i.default.createElement("label",null,/*#__PURE__*/i.default.createElement("input",{type:"checkbox",onChange:e.props.onChange,value:n,checked:l,disabled:e.props.disabled})," ",r))})))},t}(i.default.Component),ue=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).getFileName=function(){return a.props.value?"data-url"===a.props.type?a.extractFileInfo(a.props.value).name:"file-url"===a.props.type?a.props.value:"Unknown file":""},a.extractFileInfo=function(e){var t=function(e){var t,a=e.split(","),r=a[0].split(";"),n=r[0].replace("data:",""),i=r.filter(function(e){return"name"===e.split("=")[0]});t=1!==i.length?"unknown":i[0].split("=")[1];for(var l=atob(a[1]),o=[],s=0;s12&&(t-=12,l="pm"),r=o.getMinutes(),n=o.getSeconds(),i=o.getMilliseconds(),t=t.toString().padStart(2,"0"),r=r.toString().padStart(2,"0"),n=n.toString().padStart(2,"0")}return{date:e,hh:t,mm:r,ss:n,ms:i,ampm:l}},a.handleClickOutside=function(e){a.state.showTimePicker&&(!a.timePickerContainer.current||a.timePickerContainer.current.contains(e.target)||a.timeInput.current.contains(e.target)||a.setState({showTimePicker:!1}))},a.sendValue=function(){var e={target:{type:"text",value:"",name:a.props.name}};if(""===a.state.date||null===a.state.date)return a.props.onChange(e);var t=parseInt(a.state.hh);0===t&&(t=NaN),"am"===a.state.ampm?12===t&&(t=0):"pm"===a.state.ampm&&12!==t&&(t+=12),t=t.toString().padStart(2,"0");var r=a.state.mm.padStart(2,"0"),n=a.state.ss.padStart(2,"0");try{var i=new Date(a.state.date+"T"+t+":"+r+":"+n+"."+a.state.ms);e.target.value=i.toISOString().replace("Z","+00:00")}catch(t){return a.props.onChange(e)}a.props.onChange(e)},a.handleDateChange=function(e){a.setState({date:e.target.value},a.sendValue)},a.handleTimeChange=function(e){a.setState(s({},e),a.sendValue)},a.showTimePicker=function(){a.setState({showTimePicker:!0})},a.state=s({},a.getStateFromProps(),{showTimePicker:!1}),a.timeInput=/*#__PURE__*/i.default.createRef(),a.timePickerContainer=/*#__PURE__*/i.default.createRef(),a}u(t,e);var a=t.prototype;return a.componentDidUpdate=function(e,t){if(e.value!==this.props.value&&""!==this.state.hh&&"0"!==this.state.hh&&"00"!==this.state.hh){var a=!1,r=this.getStateFromProps();for(var n in r)if(r[n]!==this.state[n]){a=!0;break}a&&this.setState(s({},r))}},a.componentDidMount=function(){document.addEventListener("mousedown",this.handleClickOutside)},a.componentWillUnmount=function(){document.removeEventListener("mousedown",this.handleClickOutside)},a.render=function(){/*#__PURE__*/return i.default.createElement("div",{className:this.props.error?"rjf-datetime-field has-error":"rjf-datetime-field"},/*#__PURE__*/i.default.createElement(ae,{label:this.props.label,required:this.props.required}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-datetime-field-inner"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-datetime-field-inputs"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-datetime-field-date"},/*#__PURE__*/i.default.createElement(re,{label:"Date",type:"date",value:this.state.date,onChange:this.handleDateChange})),/*#__PURE__*/i.default.createElement("div",{className:"rjf-datetime-field-time"},/*#__PURE__*/i.default.createElement(re,{label:"Time",type:"text",value:this.state.hh+":"+this.state.mm+":"+this.state.ss+" "+this.state.ampm,onFocus:this.showTimePicker,readOnly:!0,inputRef:this.timeInput}),/*#__PURE__*/i.default.createElement("div",{ref:this.timePickerContainer},this.state.showTimePicker&&/*#__PURE__*/i.default.createElement(Y,{onChange:this.handleTimeChange,hh:this.state.hh,mm:this.state.mm,ss:this.state.ss,ampm:this.state.ampm})))),this.props.error&&this.props.error.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),this.props.help_text&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},this.props.help_text)))},t}(i.default.Component),pe=/*#__PURE__*/function(e){function t(t){var a,r,n;return(a=e.call(this,t)||this).handleSelect=function(e){var t={target:{type:a.props.type,value:e,name:a.props.name}};a.hideOptions(),a.props.onChange(t)},a.clearValue=function(e){a.handleSelect("")},a.handleSearchInputChange=function(e){var t=e.target.value;t?a.setState({searchInputValue:t,loading:!0},a.debouncedFetchOptions):a.setState({searchInputValue:t,loading:!1,options:[]})},a.fetchOptions=function(){if(""!==a.state.searchInputValue){var e=a.props.handler;if(!e)return console.error("Error: No 'handler' endpoing provided for autocomplete input."),void a.setState({loading:!1});var t=e+"?"+new URLSearchParams({field_name:a.context.fieldName,model_name:a.context.modelName,coords:j(a.props.name),query:a.state.searchInputValue});fetch(t,{method:"GET"}).then(function(e){return e.json()}).then(function(e){Array.isArray(e.results)||(e.results=[]),a.setState(function(t){return{loading:!1,options:[].concat(e.results)}})}).catch(function(e){alert("Something went wrong while fetching options"),console.error("Error:",e),a.setState({loading:!1})})}},a.showOptions=function(e){a.state.showOptions||a.setState({showOptions:!0})},a.hideOptions=function(e){a.setState({showOptions:!1,searchInputValue:"",options:[],loading:!1})},a.toggleOptions=function(e){a.setState(function(e){return e.showOptions?{showOptions:!1,searchInputValue:"",options:[],loading:!1}:{showOptions:!0}})},a.state={searchInputValue:"",showOptions:!1,options:[],loading:!1},a.optionsContainer=/*#__PURE__*/i.default.createRef(),a.searchInputRef=/*#__PURE__*/i.default.createRef(),a.input=/*#__PURE__*/i.default.createRef(),a.debouncedFetchOptions=(r=a.fetchOptions,function(){clearTimeout(n);var e=arguments,t=this;n=setTimeout(function(){r.apply(t,e)},500)}),a}u(t,e);var a=t.prototype;return a.componentDidUpdate=function(e,t){this.state.showOptions&&this.state.showOptions!==t.showOptions&&this.searchInputRef.current&&this.searchInputRef.current.focus()},a.render=function(){/*#__PURE__*/return i.default.createElement("div",{className:this.props.label?"rjf-autocomplete-field has-label":"rjf-autocomplete-field"},/*#__PURE__*/i.default.createElement(re,{label:this.props.label,type:"text",value:this.props.value,help_text:this.props.help_text,error:this.props.error,readOnly:!0,onClick:this.toggleOptions,inputRef:this.input,placeholder:this.props.placeholder,name:this.props.name,className:"rjf-autocomplete-field-input"}),this.props.value&&!this.props.readOnly&&/*#__PURE__*/i.default.createElement(F,{className:"autocomplete-field-clear",title:"Clear",onClick:this.clearValue},/*#__PURE__*/i.default.createElement($,{name:"x-circle"})," ",/*#__PURE__*/i.default.createElement("span",null,"Clear")),this.state.showOptions&&!this.props.readOnly&&/*#__PURE__*/i.default.createElement(fe,{options:this.state.options,value:this.props.value,hideOptions:this.hideOptions,onSelect:this.handleSelect,onSearchInputChange:this.handleSearchInputChange,searchInputValue:this.state.searchInputValue,containerRef:this.optionsContainer,searchInputRef:this.searchInputRef,inputRef:this.input,loading:this.state.loading,hasHelpText:(this.props.help_text||this.props.error)&&1}))},t}(i.default.Component);pe.contextType=h;var fe=/*#__PURE__*/function(e){function t(){for(var t,a=arguments.length,r=new Array(a),n=0;n0&&/*#__PURE__*/i.default.createElement(ve,{editable:e.editable,onEdit:e.onEdit},e.schema.title),e.children,e.addable&&/*#__PURE__*/i.default.createElement(F,{className:"add",onClick:function(t){return e.onAdd()},title:"object"===e.schema.type?"Add new key":"Add new item"},"object"===e.schema.type?"Add key":"Add item")))}var Oe=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).openModal=function(e){a.setState({open:!0})},a.closeModal=function(e){a.setState({open:!1,pane:"upload"})},a.togglePane=function(e){a.setState({pane:e})},a.handleFileSelect=function(e){a.props.onChange({target:{type:"text",value:e,name:a.props.name}}),a.closeModal()},a.handleFileUpload=function(e){a.newFiles.push(e.target.value),a.addExitEventListeners(),a.props.onChange(e),a.closeModal()},a.addExitEventListeners=function(){a.exitListenersAdded||a.hiddenInputRef.current&&a.hiddenInputRef.current.form&&(window.addEventListener("beforeunload",a.promptOnExit),window.addEventListener("unload",a.sendDeleteRequestOnExit),a.hiddenInputRef.current.form.addEventListener("submit",function(e){window.removeEventListener("beforeunload",a.promptOnExit),window.removeEventListener("unload",a.sendDeleteRequestOnExit)}),a.exitListenersAdded=!0)},a.promptOnExit=function(e){a.newFiles.length&&(e.preventDefault(),e.returnValue="")},a.sendDeleteRequestOnExit=function(e){a.newFiles.length&&a.sendDeleteRequest([a.newFiles],"unsaved_form_page_exit",!0)},a.clearFile=function(){window.confirm("Do you want to remove this file?")&&a.props.onChange({target:{type:"text",value:"",name:a.props.name}})},a.sendDeleteRequest=function(e,t,r){for(var n=a.props.handler||a.context.fileHandler,i=new URLSearchParams(s({},a.context.fileHandlerArgs,{coords:j(a.props.name),trigger:t})),l=0;l0?t.page+1:t.page,hasMore:e.results.length>0}})}).catch(function(e){alert("Something went wrong while retrieving media files"),console.error("Error:",e),a.setState({loading:!1})})},a.onLoadMore=function(e){a.setState({loading:!0},a.fetchList)},a.onFileDelete=function(){a.setState({page:0,files:[]},a.onLoadMore)},a.state={loading:!0,files:[],page:0,hasMore:!0},a}u(t,e);var a=t.prototype;return a.componentDidMount=function(){this.fetchList()},a.render=function(){var e=this;/*#__PURE__*/return i.default.createElement("div",{className:"rjf-upload-modal__pane"},/*#__PURE__*/i.default.createElement("h3",null,"Media library"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-upload-modal__media-container"},this.state.files.map(function(t){/*#__PURE__*/return i.default.createElement(Se,s({},t,{onClick:e.props.onFileSelect,sendDeleteRequest:e.props.sendDeleteRequest,onFileDelete:e.onFileDelete}))})),this.state.loading&&/*#__PURE__*/i.default.createElement(H,{className:"rjf-upload-modal__media-loader"}),!this.state.loading&&this.state.hasMore&&/*#__PURE__*/i.default.createElement("div",null,/*#__PURE__*/i.default.createElement(F,{onClick:this.onLoadMore,className:"upload-modal__media-load"},/*#__PURE__*/i.default.createElement($,{name:"arrow-down"})," View more")),!this.state.hasMore&&/*#__PURE__*/i.default.createElement("div",{className:"rjf-upload-modal__media-end-message"},this.state.files.length?"End of list":"No files found"))},t}(i.default.Component);function Se(e){var t=e.metadata||{};/*#__PURE__*/return i.default.createElement("div",{className:"rjf-upload-modal__media-tile"},/*#__PURE__*/i.default.createElement(Ne,{value:e.value,sendDeleteRequest:e.sendDeleteRequest,onFileDelete:e.onFileDelete}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-upload-modal__media-tile-inner",tabIndex:"0",onClick:function(){return e.onClick(e.value)}},/*#__PURE__*/i.default.createElement("img",{src:e.thumbnail?e.thumbnail:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='%23999999' viewBox='0 0 16 16'%3E%3Cpath d='M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5h-2z'/%3E%3C/svg%3E"}),e.metadata&&/*#__PURE__*/i.default.createElement("div",{className:"rjf-upload-modal__media-tile-metadata"},Object.getOwnPropertyNames(t).map(function(e){/*#__PURE__*/return i.default.createElement("span",null,t[e])}))))}var Ne=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).toggleMenu=function(e){a.setState(function(e){return{open:!e.open}})},a.handleDeleteClick=function(e){window.confirm("Do you want to delete this file?")&&(a.setState({loading:!0}),a.props.sendDeleteRequest([a.props.value],"delete_button").then(function(e){var t,r=e.status;200===r||(400===r?t="Bad request":401===r||403===r?t="You don't have permission to delete this file":404===r?t="This file does not exist on server":405===r?t="This operation is not permitted":r>405&&(t="Something went wrong while deleting file")),a.setState({loading:!1,open:!1}),t?alert(t):a.props.onFileDelete()}).catch(function(e){alert("Something went wrong while deleting file"),console.error("Error:",e),a.setState({loading:!1})}))},a.state={open:!1,loading:!1},a}return u(t,e),t.prototype.render=function(){/*#__PURE__*/return i.default.createElement("div",{className:this.state.open?"rjf-dropdown open":"rjf-dropdown"},/*#__PURE__*/i.default.createElement(F,{className:"rjf-dropdown-toggler",alterClassName:!1,title:this.state.open?"Close menu":"Open menu",onClick:this.toggleMenu},/*#__PURE__*/i.default.createElement($,{name:this.state.open?"x-lg":"three-dots-vertical"})),this.state.open&&/*#__PURE__*/i.default.createElement("div",{className:"rjf-dropdown-items"},/*#__PURE__*/i.default.createElement(F,{className:"rjf-dropdown-item rjf-text-danger",alterClassName:!1,onClick:this.handleDeleteClick},this.state.loading&&/*#__PURE__*/i.default.createElement(H,null),this.state.loading?" Deleting...":"Delete")))},t}(i.default.Component),xe=["data","schema","name","onChange","onRemove","removable","onEdit","onKeyEdit","editable","onMoveUp","onMoveDown","parentType","errorMap"];function Ce(e){var t={name:e.name,value:e.data,readOnly:S(e.schema,"readOnly","readonly"),help_text:S(e.schema,"help_text","helpText"),error:e.errorMap[j(e.name)],required:e.schema.required||!1};"string"==typeof t.error&&(t.error=[t.error]),e.schema.placeholder&&(t.placeholder=e.schema.placeholder),e.schema.handler&&(t.handler=e.schema.handler);var a,r=e.schema.type,n=S(e.schema,"choices","enum");switch(n&&(t.options=n,r="select"),e.schema.widget&&("multiselect"===e.schema.widget&&"array"!==e.parentType||(r=e.schema.widget)),r){case"string":a=re,e.schema.format?("data-url"===e.schema.format?a=ue:"file-url"===e.schema.format?a=Oe:"date-time"===k(e.schema.format)&&(a=ce),t.type=e.schema.format):t.type="text",(e.schema.minLength||0===e.schema.minLength)&&(t.minLength=e.schema.minLength),(e.schema.maxLength||0===e.schema.maxLength)&&(t.maxLength=e.schema.maxLength);break;case"fileinput":a=ue,e.schema.format&&(t.type=e.schema.format);break;case"range":case"integer":t.step="1";case"number":t.type="range"===r?"range":"number",a=re,(e.schema.minimum||0===e.schema.minimum)&&(t.min=e.schema.minimum),(e.schema.maximum||0===e.schema.maximum)&&(t.max=e.schema.maximum);break;case"boolean":case"checkbox":t.type="checkbox",a=ne;break;case"radio":t.type="radio",a=ie;break;case"select":a=le;break;case"multiselect":t.valueType=e.schema.type,a=oe;break;case"autocomplete":a=pe;break;case"textarea":a=de,(e.schema.minLength||0===e.schema.minLength)&&(t.minLength=e.schema.minLength),(e.schema.maxLength||0===e.schema.maxLength)&&(t.maxLength=e.schema.maxLength);break;default:t.type="text",a=re}/*#__PURE__*/return i.default.createElement(a,s({},t,{label:e.editable?/*#__PURE__*/i.default.createElement("span",null,e.schema.title," ",/*#__PURE__*/i.default.createElement(F,{className:"edit",onClick:e.onEdit,title:"Edit"},"Edit")):e.schema.title,onChange:function(t){return function(e,t,a){var r;r="checkbox"===e.target.type?e.target.checked:e.target.value,r=Array.isArray(r)?r.map(function(e){return g(e,t)}):g(r,t),a(e.target.name,r)}(t,e.schema.type,e.onChange)}}))}function Ae(e){var t=e.data,a=e.schema,r=e.name,n=e.onChange,l=e.onRemove,o=e.removable,u=e.onKeyEdit,d=e.editable,p=e.onMoveUp,f=e.onMoveDown,m=e.parentType,h=e.errorMap,v=c(e,xe);/*#__PURE__*/return i.default.createElement(Ee,{key:r,onRemove:o?function(e){return l(r)}:null,onMoveUp:p,onMoveDown:f},/*#__PURE__*/i.default.createElement(Ce,s({data:t,schema:a,name:r,onChange:n,onEdit:u,editable:d,parentType:m,errorMap:h},v)))}function Re(e){var t=e.data,a=e.schema,r=e.name,n=e.onChange,l=e.onAdd,o=e.onRemove,u=e.onMove,d=e.onEdit,c=e.level,p=[],f=[],m=!0,h=S(a,"min_items","minItems")||0;t.length<=h&&(m=!1);var v=!0,g=S(a,"max_items","maxItems")||100;t.length>=g&&(v=!1),a.items.hasOwnProperty("$ref")&&(a.items=e.getRef(a.items.$ref));var y=k(a.items.type),E={schema:a.items,onChange:n,onAdd:l,onRemove:o,level:c+1,removable:m,onMove:u,onEdit:d,onKeyEdit:e.onKeyEdit,parentType:"array",getRef:e.getRef,errorMap:e.errorMap};if("multiselect"===E.schema.widget)E.data=t,E.name=r,E.removable=!1,E.onMoveUp=null,E.onMoveDown=null,v=!1,p.push(Ae(E));else for(var b=function(n){E.data=t[n],E.name=O(r,n),E.onMoveUp=0===n?null:function(e){return u(O(r,n),O(r,n-1))},E.onMoveDown=n===t.length-1?null:function(e){return u(O(r,n),O(r,n+1))},"array"===y?f.push(Re(E)):"object"===y?f.push(Pe(E)):a.items.hasOwnProperty("oneOf")?f.push(/*#__PURE__*/i.default.createElement(Le,{parentArgs:e,nextArgs:s({},E),key:"oneOf_"+r+"_"+n})):a.items.hasOwnProperty("anyOf")?f.push(/*#__PURE__*/i.default.createElement(Ve,{parentArgs:e,nextArgs:s({},E),key:"anyOf_"+r+"_"+n})):p.push(Ae(E))},w=0;w0?"rjf-form-group-inner":""},C,x&&x.map(function(e,t){/*#__PURE__*/return i.default.createElement("div",{className:"rjf-error-text",key:t},e)}),f.map(function(e,t){/*#__PURE__*/return i.default.createElement("div",{className:"rjf-form-group-wrapper",key:"group_wrapper_"+r+"_"+t},/*#__PURE__*/i.default.createElement(ye,{onRemove:m?function(e){return o(O(r,t))}:null,onMoveUp:t>0?function(e){return u(O(r,t),O(r,t-1))}:null,onMoveDown:t-1&&(b.required=!0);var x={data:y,schema:b,name:E,onChange:n,onAdd:l,onRemove:o,level:c+1,removable:N,onMove:u,onEdit:d,parentType:"object",getRef:e.getRef,errorMap:e.errorMap,onKeyEdit:function(){return function(e,t,a,r,n){var i=prompt("Rename key",t);if(null!==i&&(i=i.trim())!==t){if(!i)return alert("(!) Key name can't be empty.\r\n\r\n‎");if(e.hasOwnProperty(i))return alert("(!) Duplicate keys not allowed. This key already exists.\r\n\r\n‎");var l=w(r);l.pop(),l.push(i),n(a,l=O.apply(null,l),r)}}(t,g,y,E,d)}};x.editable=N,"array"===S?p.push(Re(x)):"object"===S?p.push(Pe(x)):x.schema.hasOwnProperty("oneOf")?p.push(/*#__PURE__*/i.default.createElement(Le,{parentArgs:e,nextArgs:s({},x),key:"oneOf_"+r+"_"+m})):x.schema.hasOwnProperty("anyOf")?p.push(/*#__PURE__*/i.default.createElement(Ve,{parentArgs:e,nextArgs:s({},x),key:"anyOf_"+r+"_"+m})):p.push(Ae(x))},y=0;y-1){e=n;break}if("object"===t){if(V(a.props.nextArgs.data,i)){e=n;break}}else if("array"===t){if(T(a.props.nextArgs.data,i)){e=n;break}}else if(t===l){e=n;break}}}else{var o=a.props.parentArgs.data,s=y(o),u=a.props.parentArgs.schema[a.schemaName];if(void 0===u)return e;for(var d=0;d-1||(d[c]=l[c]));u.forEach(function(e,t){d[e]=A(o[e],a.props.parentArgs.getRef)}),this.props.parentArgs.onChange(n,d)}},a.render=function(){var e,t=this.getSchema(),a=E(t),r=this.props.nextArgs?this.props.nextArgs:this.props.parentArgs;"object"===a?(e=Pe,"object"==typeof r.data&&null!==r.data||(r.data={})):"array"===a?(e=Re,Array.isArray(r.data)||(r.data=[])):(e=Ae,r.removable=!1,r.onMoveUp=null,r.onMoveDown=null,(Array.isArray(r.data)||"object"==typeof r.data)&&(r.data=null));var n=e(s({},r,{schema:t})),l=null;return this.props.nextArgs&&(l=this.props.nextArgs.schema.title||null),/*#__PURE__*/i.default.createElement("div",{className:"rjf-form-group rjf-oneof-group"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-oneof-selector"},/*#__PURE__*/i.default.createElement(le,{value:this.state.option,options:this.getOptions(),onChange:this.handleChange,className:"rjf-oneof-selector-input",label:l})),n)},t}(i.default.Component);function Ve(e){/*#__PURE__*/return i.default.createElement(Le,s({},e,{schemaName:"anyOf"}))}function Te(e){if(!(e instanceof Object))return{isValid:!1,msg:"Schema must be an object"};var t,a=E(e);return(t="object"===a?qe(e):"array"===a?Fe(e):e.hasOwnProperty("allOf")?Je(e):e.hasOwnProperty("oneOf")?$e(e):e.hasOwnProperty("anyOf")?Ue(e):{isValid:!1,msg:"Outermost schema can only be of type array, list, object or dict"}).isValid&&e.hasOwnProperty("$defs")&&!e.$defs instanceof Object?{isValid:!1,msg:"'$defs' must be a valid JavaScript Object"}:t}function qe(e){if(!(e.hasOwnProperty("keys")||e.hasOwnProperty("properties")||e.hasOwnProperty("oneOf")||e.hasOwnProperty("anyOf")||e.hasOwnProperty("allOf")))return{isValid:!1,msg:"Schema of type '"+e.type+"' must have at least one of these keys: ['properties' or 'keys' or 'oneOf' or 'anyOf' or 'allOf']"};var t,a=e.properties||e.keys;if(a&&(t=function(e){if(!(e instanceof Object))return{isValid:!1,msg:"The 'keys' or 'properties' key must be a valid JavaScript Object"};for(var t in e)if(e.hasOwnProperty(t)){var a=e[t];if(!(a instanceof Object))return{isValid:!1,msg:"Key '"+t+"' must be a valid JavaScript Object"};var r={isValid:!0},n=k(a.type);if(n?"object"===n?r=qe(a):"array"===n&&(r=Fe(a)):r=a.hasOwnProperty("$ref")?He(a):a.hasOwnProperty("oneOf")?$e(a):a.hasOwnProperty("anyOf")?Ue(a):a.hasOwnProperty("allOf")?Je(a):{isValid:!1,msg:"Key '"+t+"' must have a 'type' or a '$ref"},!r.isValid)return r}return{isValid:!0,msg:""}}(a),!t.isValid))return t;if(e.hasOwnProperty("additionalProperties")){if(!(e.additionalProperties instanceof Object)&&"boolean"!=typeof e.additionalProperties)return{isValid:!1,msg:"'additionalProperties' must be either a JavaScript boolean or a JavaScript object"};if(e.additionalProperties instanceof Object)if(e.additionalProperties.hasOwnProperty("$ref")){if(!(t=He(e.additionalProperties)).isValid)return t}else{var r=k(e.additionalProperties.type);if("object"===r)return qe(e.additionalProperties);if("array"===r)return Te(e.additionalProperties)}}return e.hasOwnProperty("oneOf")&&!(t=$e(e)).isValid||e.hasOwnProperty("anyOf")&&!(t=Ue(e)).isValid||e.hasOwnProperty("allOf")&&!(t=Je(e)).isValid?t:{isValid:!0,msg:""}}function Fe(e){if(!e.hasOwnProperty("items"))return{isValid:!1,msg:"Schema of type '"+e.type+"' must have a key called 'items'"};if(!(e.items instanceof Object))return{isValid:!1,msg:"The 'items' key must be a valid JavaScript Object'"};var t=k(e.items.type);if(t){if("object"===t)return qe(e.items);if("array"===t)return Fe(e.items)}else{if(e.items.hasOwnProperty("$ref"))return He(e.items);if(!e.items.hasOwnProperty("oneOf")&&!e.items.hasOwnProperty("anyOf")&&!e.items.hasOwnProperty("allOf"))return{isValid:!1,msg:"Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf' or 'allOf'"}}return e.hasOwnProperty("oneOf")&&(validation=$e(e.items),!validation.isValid)||e.hasOwnProperty("anyOf")&&(validation=Ue(e.items),!validation.isValid)||e.hasOwnProperty("allOf")&&(validation=Je(e.items),!validation.isValid)?validation:{isValid:!0,msg:""}}function He(e){return"string"!=typeof e.$ref?{isValid:!1,msg:"'$ref' keyword must be a string"}:e.$ref.startsWith("#")?e.$ref.lenght>1&&!e.$ref.startsWith("#/")?{isValid:!1,msg:"Invalid '$ref' path"}:{isValid:!0,msg:""}:{isValid:!1,msg:"'$ref' value must begin with a hash (#) character"}}function $e(e){return ze(e,"oneOf")}function Ue(e){return ze(e,"anyOf")}function Je(e){var t=ze(e,"allOf");if(!t.isValid)return t;for(var a=e.allOf,r=0;rparseInt(l)&&this.addError(a,"Maximum "+l+" items allowed."),N(e,"uniqueItems")&&("array"===n||"object"===n?t.length!==new Set(t.map(function(e){return JSON.stringify(e)})).size&&this.addError(a,"All items in this list must be unique."):t.length!==new Set(t).size&&this.addError(a,"All items in this list must be unique.")),o){var s=t.find(function(e){return-1===o.indexOf(e)});void 0!==s&&this.addError(a,'Invalid choice + "'+s+'"')}var u=this.getValidator(n);if(u)for(var d=0;d-1&&(o.required=!0);var s=k(o.type),u=this.getValidator(s);if(!u)return void this.addError(a,'Unsupported type "'+s+'" for object properties (keys).');u(o,t[l],this.joinCoords([a,l]))}e.hasOwnProperty("allOf")&&this.validateAllOf(e,t,a)}}},this.validateAllOf=function(e,t,a){for(var r={type:"object",properties:{}},n=0;nparseInt(e.maxLength)&&this.addError(a,"This value may not be longer than "+e.maxLength+" characters."),k(e.format)){case"email":r=this.validateEmail;break;case"date":r=this.validateDate;break;case"time":r=this.validateTime;break;case"date-time":r=this.validateDateTime}r&&r.call(this,e,t,a)}}else this.addError(a,"This value is invalid. Must be a valid string.");else this.addError(a,"This field is required.")},this.validateBoolean=function(e,t,a){e.required&&null==t?this.addError(a,"This field is required."):"boolean"!=typeof t&&null!=t&&this.addError(a,"Invalid value.")},this.validateInteger=function(e,t,a){e.required&&null==t?this.addError(a,"This field is required."):null!==t&&("number"==typeof t&&t===parseInt(t)?this.validateNumber(e,t,a):this.addError(a,"Invalid value. Only integers allowed."))},this.validateNumber=function(e,t,a){e.required&&null==t?this.addError(a,"This field is required."):null!==t&&("number"==typeof t?((e.minimum||0===e.minimum)&&te.maximum&&this.addError(a,"This value must not be greater than "+e.minimum),(e.exclusiveMinimum||0===e.exclusiveMinimum)&&t<=e.exclusiveMinimum&&this.addError(a,"This value must be greater than "+e.exclusiveMinimum),(e.exclusiveMaximum||0===e.exclusiveMaximum)&&t>=e.exclusiveMaximum&&this.addError(a,"This value must be less than "+e.exclusiveMaximum),(e.multipleOf||0===e.multipleOf)&&100*t%(100*e.multipleOf)/100&&this.addError(a,"This value must be a multiple of "+e.multipleOf)):this.addError(a,"Invalid value. Only numbers allowed."))},this.validateEmail=function(e,t,a){t.indexOf(" ")>-1?this.addError(a,"Enter a valid email address."):t.length>320&&this.addError(a,"Email may not be longer than 320 characters")},this.validateDate=function(e,t,a){},this.validateTime=function(e,t,a){},this.validateDateTime=function(e,t,a){}}function Qe(e){this.containerId=e.containerId,this.dataInputId=e.dataInputId,this.schema=e.schema,this.data=e.data,this.errorMap=e.errorMap,this.fileHandler=e.fileHandler,this.fileHandlerArgs=e.fileHandlerArgs||{},this.eventListeners=null,this._dataSynced=!1,this.addEventListener=function(e,t){null===this.eventListeners&&(this.eventListeners={}),this.eventListeners.hasOwnProperty(e)||(this.eventListeners[e]=new Set),this.eventListeners[e].add(t)},this.onChange=function(e){this.data=e.data,this._dataSynced?this.eventListeners&&this.eventListeners.hasOwnProperty("change")&&this.eventListeners.change.size&&this.eventListeners.change.forEach(function(t){return t(e)}):this._dataSynced=!0},this.onChange=this.onChange.bind(this),this.render=function(){try{o.default.render(/*#__PURE__*/i.default.createElement(tt,{schema:this.schema,dataInputId:this.dataInputId,data:this.data,errorMap:this.errorMap,fileHandler:this.fileHandler,fileHandlerArgs:this.fileHandlerArgs,onChange:this.onChange}),document.getElementById(this.containerId))}catch(e){o.default.render(/*#__PURE__*/i.default.createElement(at,{error:e}),document.getElementById(this.containerId))}},this.update=function(e){this.schema=e.schema||this.schema,this.data=e.data||this.data,this.errorMap=e.errorMap||this.errorMap,this.render()},this.getSchema=function(){return this.schema},this.getData=function(){return this.data},this.validate=function(){return new Ze(this.getSchema()).validate(this.getData())}}var et={},tt=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).populateDataInput=function(e){a.dataInput.value=JSON.stringify(e)},a.handleChange=function(e){a.setState({editorState:e})},a.state={editorState:Be.create(t.schema,t.data)},a.prevEditorState=a.state.editorState,a.dataInput=document.getElementById(t.dataInputId),a}u(t,e);var a=t.prototype;return a.componentDidMount=function(){this.props.onChange({data:this.state.editorState.getData()}),this.populateDataInput(this.state.editorState.getData())},a.componentDidUpdate=function(e,t){if(this.props.schema===e.schema)this.props.data===e.data?(this.state.editorState!==t.editorState&&this.populateDataInput(this.state.editorState.getData()),this.props.onChange&&this.state.editorState!==t.editorState&&this.props.onChange({schema:this.state.editorState.getSchema(),data:this.state.editorState.getData(),prevSchema:t.editorState.getSchema(),prevData:t.editorState.getData()})):this.setState({editorState:Be.update(this.state.editorState,this.props.data)});else{var a=this.props.schema,r=this.props.data!==e.data?this.props.data:this.state.editorState.getData();this.setState({editorState:Be.create(a,r)})}},a.render=function(){/*#__PURE__*/return i.default.createElement(Ke,{editorState:this.state.editorState,onChange:this.handleChange,fileHandler:this.props.fileHandler,fileHandlerArgs:this.props.fileHandlerArgs,errorMap:this.props.errorMap})},t}(i.default.Component);function at(e){/*#__PURE__*/return i.default.createElement("div",{style:{color:"#f00"}},/*#__PURE__*/i.default.createElement("p",null,"(!) ",e.error.toString()),/*#__PURE__*/i.default.createElement("p",null,"Check browser console for more details about the error."))}e.DataValidator=Ze,e.EditorState=Be,e.ReactJSONForm=Ke,e.createForm=function(e){var t=new Qe(e);return et[e.containerId]=t,t},e.getFormInstance=function(e){return et[e]}}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-modal"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-modal","react-dom"],t):t((e||self).reactJsonForm={},e.React,e.ReactModal,e.ReactDOM)}(this,function(e,t,a,r){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/n(t),l=/*#__PURE__*/n(a),o=/*#__PURE__*/n(r);function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0||(n[a]=e[a]);return n}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,r=new Array(t);a=a)return e.default;var r=[];if(e.default&&(r=[].concat(e.default)),0===a)return r;e.items.hasOwnProperty("$ref")&&(e.items=t(e.items.$ref));var n=k(e.items.type);if(n||(Array.isArray(e.items.oneOf)?n=E(e.items.oneOf[0]):Array.isArray(e.items.anyOf)?n=E(e.items.anyOf[0]):Array.isArray(e.items.allOf)&&(n=E(e.items.allOf[0]))),"array"===n){for(;r.length=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.")}(e);!(a=r()).done;)if(!t.has(a.value))return!1;return!0}(keyset2,keyset1))return!1}else if(r=keyset2,n=keyset1,r.size!==n.size||!Array.from(r).every(function(e){return n.has(e)}))return!1;for(var l in i)if(i.hasOwnProperty(l)){if(!e.hasOwnProperty(l))return!1;var o=k(i[l].type),s=y(e[l]);if("number"===o&&-1===["number","integer","null"].indexOf(s))return!1;if("integer"===o&&-1===["number","integer","null"].indexOf(s))return!1;if("boolean"===o&&-1===["boolean","null"].indexOf(s))return!1;if("string"===o&&"string"!==s)return!1}return!0}function q(e,t){var a=y(e);if(E(t)!==a)return!1;for(var r=t.items.type,n=0;n12?1:"hh"!==e&&t>59?0:t},t.handleChange=function(e){var a,r=e.target.dataset.name,n=e.target.value;if(!isNaN(n)){var i=t.validateValue(r,parseInt(n)||0);"hh"!==r||"0"!==n&&""!==n&&"00"!==n||1!==i||(i=0),n.startsWith("0")&&i<10&&0!==i&&(i=i.toString().padStart(2,"0")),t.sendValue(((a={})[r]=""!==n?i.toString():"",a))}},t.handleKeyDown=function(e){var a;if(38===e.keyCode||40===e.keyCode){var r=e.target.dataset.name,n=parseInt(e.target.value)||0;38===e.keyCode?n++:40===e.keyCode&&n--,t.sendValue(((a={})[r]=t.validateValue(r,n).toString().padStart(2,"0"),a))}},t.handleSpin=function(e,a){var r,n=t.props[e];"ampm"===e?n="am"===n?"pm":"am":(n=parseInt(n)||0,"up"===a?n++:n--,n=t.validateValue(e,n).toString().padStart(2,"0")),t.sendValue(((r={})[e]=n,r))},t.handleBlur=function(e){var a,r=t.validateValue(e.target.dataset.name,parseInt(e.target.value)||0);r<10&&t.sendValue(((a={})[e.target.dataset.name]=r.toString().padStart(2,"0"),a))},t}u(t,e);var a=t.prototype;return a.componentWillUnmount=function(){var e={hh:this.validateValue("hh",this.props.hh).toString().padStart(2,"0"),mm:this.validateValue("mm",this.props.mm).toString().padStart(2,"0"),ss:this.validateValue("ss",this.props.ss).toString().padStart(2,"0")};this.sendValue(e)},a.render=function(){var e=this;/*#__PURE__*/return i.default.createElement("div",{className:"rjf-time-picker"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-row rjf-time-picker-labels"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},"Hrs"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},"Min"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},"Sec"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},"am/pm")),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-row"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(H,{onClick:function(){return e.handleSpin("hh","up")}},/*#__PURE__*/i.default.createElement(U,{name:"chevron-up"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(H,{onClick:function(){return e.handleSpin("mm","up")}},/*#__PURE__*/i.default.createElement(U,{name:"chevron-up"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(H,{onClick:function(){return e.handleSpin("ss","up")}},/*#__PURE__*/i.default.createElement(U,{name:"chevron-up"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(H,{onClick:function(){return e.handleSpin("ampm","up")}},/*#__PURE__*/i.default.createElement(U,{name:"chevron-up"})))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-row rjf-time-picker-values"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement("input",{type:"text","data-name":"hh",value:this.props.hh,onChange:this.handleChange,onBlur:this.handleBlur,onKeyDown:this.handleKeyDown})),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"},":"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement("input",{type:"text","data-name":"mm",value:this.props.mm,onChange:this.handleChange,onBlur:this.handleBlur,onKeyDown:this.handleKeyDown})),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"},":"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement("input",{type:"text","data-name":"ss",value:this.props.ss,onChange:this.handleChange,onBlur:this.handleBlur,onKeyDown:this.handleKeyDown})),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},this.props.ampm)),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-row"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(H,{onClick:function(){return e.handleSpin("hh","down")}},/*#__PURE__*/i.default.createElement(U,{name:"chevron-down"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(H,{onClick:function(){return e.handleSpin("mm","down")}},/*#__PURE__*/i.default.createElement(U,{name:"chevron-down"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(H,{onClick:function(){return e.handleSpin("ss","down")}},/*#__PURE__*/i.default.createElement(U,{name:"chevron-down"}))),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col rjf-time-picker-col-sm"}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-time-picker-col"},/*#__PURE__*/i.default.createElement(H,{onClick:function(){return e.handleSpin("ampm","down")}},/*#__PURE__*/i.default.createElement(U,{name:"chevron-down"})))))},t}(i.default.Component),X=["label","help_text","error","inputRef"],Z=["label","help_text","error","value"],Q=["label","help_text","error","value","options"],ee=["label","help_text","error","value","options"],te=["label","value"],ae=["label","help_text","error","inputRef"];function re(e){return e.label?/*#__PURE__*/i.default.createElement("label",{className:e.required?"rjf-required":null},e.children,e.children&&" ",e.label):null}function ne(e){var t=e.label,a=e.help_text,r=e.error,n=e.inputRef,l=c(e,X);return"string"===l.type&&(l.type="text"),n&&(l.ref=n),null===l.value&&(l.value=""),/*#__PURE__*/i.default.createElement("div",null,/*#__PURE__*/i.default.createElement(re,{label:t,required:l.required}),/*#__PURE__*/i.default.createElement("div",{className:r?"rjf-input-group has-error":"rjf-input-group"},/*#__PURE__*/i.default.createElement("input",l),r&&r.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),a&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},a)))}function ie(e){var t=e.label,a=e.help_text,r=e.error,n=e.value,l=c(e,Z);return t||(t=l.name.toUpperCase()),"bool"===l.type&&(l.type="checkbox"),void 0===l.checked&&(l.checked=n),""!==l.checked&&null!=l.checked||(l.checked=!1),l.readOnly&&(l.disabled=!0),/*#__PURE__*/i.default.createElement("div",{className:r?"rjf-check-input has-error":"rjf-check-input"},/*#__PURE__*/i.default.createElement(re,{label:t,required:l.required},/*#__PURE__*/i.default.createElement("input",l)),r&&r.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),a&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},a))}function le(e){var t=e.label,a=e.help_text,r=e.error,n=e.value,l=e.options,o=c(e,Q);return o.readOnly&&(o.disabled=!0),/*#__PURE__*/i.default.createElement("div",{className:r?"rjf-check-input has-error":"rjf-check-input"},/*#__PURE__*/i.default.createElement(re,{label:t,required:o.required}),l.map(function(e,t){var a,r;return"object"==typeof e?(a=e.title||e.label,r=e.value):("boolean"==typeof(a=e)&&(a=v(a.toString())),r=e),/*#__PURE__*/i.default.createElement("label",{key:a+"_"+r+"_"+t},/*#__PURE__*/i.default.createElement("input",s({},o,{value:r,checked:r===n}))," ",a)}),r&&r.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),a&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},a))}function oe(e){var t=e.label,a=e.help_text,r=e.error,n=e.value,l=e.options,o=c(e,ee);return o.readOnly&&(o.disabled=!0),n||!1===n||0===n||(n=""),/*#__PURE__*/i.default.createElement("div",null,/*#__PURE__*/i.default.createElement(re,{label:t,required:o.required}),/*#__PURE__*/i.default.createElement("div",{className:r?"rjf-input-group has-error":"rjf-input-group"},/*#__PURE__*/i.default.createElement("select",s({value:n},o),/*#__PURE__*/i.default.createElement("option",{disabled:!0,value:"",key:"__placehlder"},"Select..."),l.map(function(e,t){var a,r;return"object"==typeof e?(a=e.title||e.label,r=e.value):("boolean"==typeof(a=e)&&(a=v(a.toString())),r=e),/*#__PURE__*/i.default.createElement("option",{value:r,key:a+"_"+r+"_"+t},a)})),r&&r.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),a&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},a)))}var se=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).handleChange=function(e){var t=[].concat(a.props.value),r=e.target.value;typeof r!==a.props.valueType&&(r=g(r,a.props.valueType)),e.target.checked?t.push(r):t=t.filter(function(e){return e!==r}),a.props.onChange({target:{type:a.props.type,value:t,name:a.props.name}})},a.showOptions=function(e){a.state.showOptions||a.setState({showOptions:!0})},a.hideOptions=function(e){a.setState({showOptions:!1})},a.toggleOptions=function(e){a.setState(function(e){return{showOptions:!e.showOptions}})},a.state={showOptions:!1},a.optionsContainer=/*#__PURE__*/i.default.createRef(),a.input=/*#__PURE__*/i.default.createRef(),a}return u(t,e),t.prototype.render=function(){/*#__PURE__*/return i.default.createElement("div",{className:"rjf-multiselect-field"},/*#__PURE__*/i.default.createElement(ne,{label:this.props.label,type:"text",value:this.props.value.length?this.props.value.length+" selected":"Select...",help_text:this.props.help_text,error:this.props.error,onClick:this.toggleOptions,readOnly:!0,inputRef:this.input,className:"rjf-multiselect-field-input"}),this.state.showOptions&&/*#__PURE__*/i.default.createElement(ue,{options:this.props.options,value:this.props.value,hideOptions:this.hideOptions,onChange:this.handleChange,containerRef:this.optionsContainer,inputRef:this.input,disabled:this.props.readOnly,hasHelpText:(this.props.help_text||this.props.error)&&1}))},t}(i.default.Component),ue=/*#__PURE__*/function(e){function t(){for(var t,a=arguments.length,r=new Array(a),n=0;n-1,o="rjf-multiselect-field-option";return l&&(o+=" selected"),e.props.disabled&&(o+=" disabled"),/*#__PURE__*/i.default.createElement("div",{key:r+"_"+n+"_"+a,className:o},/*#__PURE__*/i.default.createElement("label",null,/*#__PURE__*/i.default.createElement("input",{type:"checkbox",onChange:e.props.onChange,value:n,checked:l,disabled:e.props.disabled})," ",r))})))},t}(i.default.Component),de=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).getFileName=function(){return a.props.value?"data-url"===a.props.type?a.extractFileInfo(a.props.value).name:"file-url"===a.props.type?a.props.value:"Unknown file":""},a.extractFileInfo=function(e){var t=function(e){var t,a=e.split(","),r=a[0].split(";"),n=r[0].replace("data:",""),i=r.filter(function(e){return"name"===e.split("=")[0]});t=1!==i.length?"unknown":i[0].split("=")[1];for(var l=atob(a[1]),o=[],s=0;s12&&(t-=12,l="pm"),r=o.getMinutes(),n=o.getSeconds(),i=o.getMilliseconds(),t=t.toString().padStart(2,"0"),r=r.toString().padStart(2,"0"),n=n.toString().padStart(2,"0")}return{date:e,hh:t,mm:r,ss:n,ms:i,ampm:l}},a.handleClickOutside=function(e){a.state.showTimePicker&&(!a.timePickerContainer.current||a.timePickerContainer.current.contains(e.target)||a.timeInput.current.contains(e.target)||a.setState({showTimePicker:!1}))},a.sendValue=function(){var e={target:{type:"text",value:"",name:a.props.name}};if(""===a.state.date||null===a.state.date)return a.props.onChange(e);var t=parseInt(a.state.hh);0===t&&(t=NaN),"am"===a.state.ampm?12===t&&(t=0):"pm"===a.state.ampm&&12!==t&&(t+=12),t=t.toString().padStart(2,"0");var r=a.state.mm.padStart(2,"0"),n=a.state.ss.padStart(2,"0");try{var i=new Date(a.state.date+"T"+t+":"+r+":"+n+"."+a.state.ms);e.target.value=i.toISOString().replace("Z","+00:00")}catch(t){return a.props.onChange(e)}a.props.onChange(e)},a.handleDateChange=function(e){a.setState({date:e.target.value},a.sendValue)},a.handleTimeChange=function(e){a.setState(s({},e),a.sendValue)},a.showTimePicker=function(){a.setState({showTimePicker:!0})},a.state=s({},a.getStateFromProps(),{showTimePicker:!1}),a.timeInput=/*#__PURE__*/i.default.createRef(),a.timePickerContainer=/*#__PURE__*/i.default.createRef(),a}u(t,e);var a=t.prototype;return a.componentDidUpdate=function(e,t){if(e.value!==this.props.value&&""!==this.state.hh&&"0"!==this.state.hh&&"00"!==this.state.hh){var a=!1,r=this.getStateFromProps();for(var n in r)if(r[n]!==this.state[n]){a=!0;break}a&&this.setState(s({},r))}},a.componentDidMount=function(){document.addEventListener("mousedown",this.handleClickOutside)},a.componentWillUnmount=function(){document.removeEventListener("mousedown",this.handleClickOutside)},a.render=function(){/*#__PURE__*/return i.default.createElement("div",{className:this.props.error?"rjf-datetime-field has-error":"rjf-datetime-field"},/*#__PURE__*/i.default.createElement(re,{label:this.props.label,required:this.props.required}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-datetime-field-inner"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-datetime-field-inputs"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-datetime-field-date"},/*#__PURE__*/i.default.createElement(ne,{label:"Date",type:"date",value:this.state.date,onChange:this.handleDateChange})),/*#__PURE__*/i.default.createElement("div",{className:"rjf-datetime-field-time"},/*#__PURE__*/i.default.createElement(ne,{label:"Time",type:"text",value:this.state.hh+":"+this.state.mm+":"+this.state.ss+" "+this.state.ampm,onFocus:this.showTimePicker,readOnly:!0,inputRef:this.timeInput}),/*#__PURE__*/i.default.createElement("div",{ref:this.timePickerContainer},this.state.showTimePicker&&/*#__PURE__*/i.default.createElement(G,{onChange:this.handleTimeChange,hh:this.state.hh,mm:this.state.mm,ss:this.state.ss,ampm:this.state.ampm})))),this.props.error&&this.props.error.map(function(e,t){/*#__PURE__*/return i.default.createElement("span",{className:"rjf-error-text",key:t},e)}),this.props.help_text&&/*#__PURE__*/i.default.createElement("span",{className:"rjf-help-text"},this.props.help_text)))},t}(i.default.Component),fe=/*#__PURE__*/function(e){function t(t){var a,r,n;return(a=e.call(this,t)||this).handleSelect=function(e){var t={target:{type:a.props.type,value:e,name:a.props.name}};a.hideOptions(),a.props.onChange(t)},a.clearValue=function(e){a.handleSelect("")},a.handleSearchInputChange=function(e){var t=e.target.value;t?a.setState({searchInputValue:t,loading:!0},a.debouncedFetchOptions):a.setState({searchInputValue:t,loading:!1,options:[]})},a.fetchOptions=function(){if(""!==a.state.searchInputValue){var e=a.props.handler;if(!e)return console.error("Error: No 'handler' endpoing provided for autocomplete input."),void a.setState({loading:!1});var t=e+"?"+new URLSearchParams({field_name:a.context.fieldName,model_name:a.context.modelName,coords:j(a.props.name),query:a.state.searchInputValue});fetch(t,{method:"GET"}).then(function(e){return e.json()}).then(function(e){Array.isArray(e.results)||(e.results=[]),a.setState(function(t){return{loading:!1,options:[].concat(e.results)}})}).catch(function(e){alert("Something went wrong while fetching options"),console.error("Error:",e),a.setState({loading:!1})})}},a.showOptions=function(e){a.state.showOptions||a.setState({showOptions:!0})},a.hideOptions=function(e){a.setState({showOptions:!1,searchInputValue:"",options:[],loading:!1})},a.toggleOptions=function(e){a.setState(function(e){return e.showOptions?{showOptions:!1,searchInputValue:"",options:[],loading:!1}:{showOptions:!0}})},a.state={searchInputValue:"",showOptions:!1,options:[],loading:!1},a.optionsContainer=/*#__PURE__*/i.default.createRef(),a.searchInputRef=/*#__PURE__*/i.default.createRef(),a.input=/*#__PURE__*/i.default.createRef(),a.debouncedFetchOptions=(r=a.fetchOptions,function(){clearTimeout(n);var e=arguments,t=this;n=setTimeout(function(){r.apply(t,e)},500)}),a}u(t,e);var a=t.prototype;return a.componentDidUpdate=function(e,t){this.state.showOptions&&this.state.showOptions!==t.showOptions&&this.searchInputRef.current&&this.searchInputRef.current.focus()},a.render=function(){/*#__PURE__*/return i.default.createElement("div",{className:this.props.label?"rjf-autocomplete-field has-label":"rjf-autocomplete-field"},/*#__PURE__*/i.default.createElement(ne,{label:this.props.label,type:"text",value:this.props.value,help_text:this.props.help_text,error:this.props.error,readOnly:!0,onClick:this.toggleOptions,inputRef:this.input,placeholder:this.props.placeholder,name:this.props.name,className:"rjf-autocomplete-field-input"}),this.props.value&&!this.props.readOnly&&/*#__PURE__*/i.default.createElement(H,{className:"autocomplete-field-clear",title:"Clear",onClick:this.clearValue},/*#__PURE__*/i.default.createElement(U,{name:"x-circle"})," ",/*#__PURE__*/i.default.createElement("span",null,"Clear")),this.state.showOptions&&!this.props.readOnly&&/*#__PURE__*/i.default.createElement(me,{options:this.state.options,value:this.props.value,hideOptions:this.hideOptions,onSelect:this.handleSelect,onSearchInputChange:this.handleSearchInputChange,searchInputValue:this.state.searchInputValue,containerRef:this.optionsContainer,searchInputRef:this.searchInputRef,inputRef:this.input,loading:this.state.loading,hasHelpText:(this.props.help_text||this.props.error)&&1}))},t}(i.default.Component);fe.contextType=h;var me=/*#__PURE__*/function(e){function t(){for(var t,a=arguments.length,r=new Array(a),n=0;n0&&/*#__PURE__*/i.default.createElement(ge,{editable:e.editable,onEdit:e.onEdit},e.schema.title),e.children,e.addable&&/*#__PURE__*/i.default.createElement(H,{className:"add",onClick:function(t){return e.onAdd()},title:"object"===e.schema.type?"Add new key":"Add new item"},"object"===e.schema.type?"Add key":"Add item")))}var we=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).openModal=function(e){a.setState({open:!0})},a.closeModal=function(e){a.setState({open:!1,pane:"upload"})},a.togglePane=function(e){a.setState({pane:e})},a.handleFileSelect=function(e){a.props.onChange({target:{type:"text",value:e,name:a.props.name}}),a.closeModal()},a.handleFileUpload=function(e){a.newFiles.push(e.target.value),a.addExitEventListeners(),a.props.onChange(e),a.closeModal()},a.addExitEventListeners=function(){a.exitListenersAdded||a.hiddenInputRef.current&&a.hiddenInputRef.current.form&&(window.addEventListener("beforeunload",a.promptOnExit),window.addEventListener("unload",a.sendDeleteRequestOnExit),a.hiddenInputRef.current.form.addEventListener("submit",function(e){window.removeEventListener("beforeunload",a.promptOnExit),window.removeEventListener("unload",a.sendDeleteRequestOnExit)}),a.exitListenersAdded=!0)},a.promptOnExit=function(e){a.newFiles.length&&(e.preventDefault(),e.returnValue="")},a.sendDeleteRequestOnExit=function(e){a.newFiles.length&&a.sendDeleteRequest([a.newFiles],"unsaved_form_page_exit",!0)},a.clearFile=function(){window.confirm("Do you want to remove this file?")&&a.props.onChange({target:{type:"text",value:"",name:a.props.name}})},a.sendDeleteRequest=function(e,t,r){for(var n=a.props.handler||a.context.fileHandler,i=new URLSearchParams(s({},a.context.fileHandlerArgs,{coords:j(a.props.name),trigger:t})),l=0;l0?t.page+1:t.page,hasMore:e.results.length>0}})}).catch(function(e){alert("Something went wrong while retrieving media files"),console.error("Error:",e),a.setState({loading:!1})})},a.onLoadMore=function(e){a.setState({loading:!0},a.fetchList)},a.onFileDelete=function(){a.setState({page:0,files:[]},a.onLoadMore)},a.state={loading:!0,files:[],page:0,hasMore:!0},a}u(t,e);var a=t.prototype;return a.componentDidMount=function(){this.fetchList()},a.render=function(){var e=this;/*#__PURE__*/return i.default.createElement("div",{className:"rjf-upload-modal__pane"},/*#__PURE__*/i.default.createElement("h3",null,"Media library"),/*#__PURE__*/i.default.createElement("div",{className:"rjf-upload-modal__media-container"},this.state.files.map(function(t){/*#__PURE__*/return i.default.createElement(Ne,s({},t,{onClick:e.props.onFileSelect,sendDeleteRequest:e.props.sendDeleteRequest,onFileDelete:e.onFileDelete}))})),this.state.loading&&/*#__PURE__*/i.default.createElement($,{className:"rjf-upload-modal__media-loader"}),!this.state.loading&&this.state.hasMore&&/*#__PURE__*/i.default.createElement("div",null,/*#__PURE__*/i.default.createElement(H,{onClick:this.onLoadMore,className:"upload-modal__media-load"},/*#__PURE__*/i.default.createElement(U,{name:"arrow-down"})," View more")),!this.state.hasMore&&/*#__PURE__*/i.default.createElement("div",{className:"rjf-upload-modal__media-end-message"},this.state.files.length?"End of list":"No files found"))},t}(i.default.Component);function Ne(e){var t=e.metadata||{};/*#__PURE__*/return i.default.createElement("div",{className:"rjf-upload-modal__media-tile"},/*#__PURE__*/i.default.createElement(xe,{value:e.value,sendDeleteRequest:e.sendDeleteRequest,onFileDelete:e.onFileDelete}),/*#__PURE__*/i.default.createElement("div",{className:"rjf-upload-modal__media-tile-inner",tabIndex:"0",onClick:function(){return e.onClick(e.value)}},/*#__PURE__*/i.default.createElement("img",{src:e.thumbnail?e.thumbnail:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='%23999999' viewBox='0 0 16 16'%3E%3Cpath d='M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5h-2z'/%3E%3C/svg%3E"}),e.metadata&&/*#__PURE__*/i.default.createElement("div",{className:"rjf-upload-modal__media-tile-metadata"},Object.getOwnPropertyNames(t).map(function(e){/*#__PURE__*/return i.default.createElement("span",null,t[e])}))))}var xe=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).toggleMenu=function(e){a.setState(function(e){return{open:!e.open}})},a.handleDeleteClick=function(e){window.confirm("Do you want to delete this file?")&&(a.setState({loading:!0}),a.props.sendDeleteRequest([a.props.value],"delete_button").then(function(e){var t,r=e.status;200===r||(400===r?t="Bad request":401===r||403===r?t="You don't have permission to delete this file":404===r?t="This file does not exist on server":405===r?t="This operation is not permitted":r>405&&(t="Something went wrong while deleting file")),a.setState({loading:!1,open:!1}),t?alert(t):a.props.onFileDelete()}).catch(function(e){alert("Something went wrong while deleting file"),console.error("Error:",e),a.setState({loading:!1})}))},a.state={open:!1,loading:!1},a}return u(t,e),t.prototype.render=function(){/*#__PURE__*/return i.default.createElement("div",{className:this.state.open?"rjf-dropdown open":"rjf-dropdown"},/*#__PURE__*/i.default.createElement(H,{className:"rjf-dropdown-toggler",alterClassName:!1,title:this.state.open?"Close menu":"Open menu",onClick:this.toggleMenu},/*#__PURE__*/i.default.createElement(U,{name:this.state.open?"x-lg":"three-dots-vertical"})),this.state.open&&/*#__PURE__*/i.default.createElement("div",{className:"rjf-dropdown-items"},/*#__PURE__*/i.default.createElement(H,{className:"rjf-dropdown-item rjf-text-danger",alterClassName:!1,onClick:this.handleDeleteClick},this.state.loading&&/*#__PURE__*/i.default.createElement($,null),this.state.loading?" Deleting...":"Delete")))},t}(i.default.Component),Ce=["data","schema","name","onChange","onRemove","removable","onEdit","onKeyEdit","editable","onMoveUp","onMoveDown","parentType","errorMap"];function Ae(e){var t={name:e.name,value:e.data,readOnly:S(e.schema,"readOnly","readonly"),help_text:S(e.schema,"help_text","helpText"),error:e.errorMap[j(e.name)],required:e.schema.required||!1};"string"==typeof t.error&&(t.error=[t.error]),e.schema.placeholder&&(t.placeholder=e.schema.placeholder),e.schema.handler&&(t.handler=e.schema.handler);var a,r=e.schema.type,n=S(e.schema,"choices","enum");switch(n&&(t.options=n,r="select"),e.schema.widget&&("multiselect"===e.schema.widget&&"array"!==e.parentType||(r=e.schema.widget)),r){case"string":a=ne,e.schema.format?("data-url"===e.schema.format?a=de:"file-url"===e.schema.format?a=we:"date-time"===k(e.schema.format)&&(a=pe),t.type=e.schema.format):t.type="text",(e.schema.minLength||0===e.schema.minLength)&&(t.minLength=e.schema.minLength),(e.schema.maxLength||0===e.schema.maxLength)&&(t.maxLength=e.schema.maxLength);break;case"fileinput":a=de,e.schema.format&&(t.type=e.schema.format);break;case"range":case"integer":t.step="1";case"number":t.type="range"===r?"range":"number",a=ne,(e.schema.minimum||0===e.schema.minimum)&&(t.min=e.schema.minimum),(e.schema.maximum||0===e.schema.maximum)&&(t.max=e.schema.maximum);break;case"boolean":case"checkbox":t.type="checkbox",a=ie;break;case"radio":t.type="radio",a=le;break;case"select":a=oe;break;case"multiselect":t.valueType=e.schema.type,a=se;break;case"autocomplete":a=fe;break;case"textarea":a=ce,(e.schema.minLength||0===e.schema.minLength)&&(t.minLength=e.schema.minLength),(e.schema.maxLength||0===e.schema.maxLength)&&(t.maxLength=e.schema.maxLength);break;default:t.type="text",a=ne}/*#__PURE__*/return i.default.createElement(a,s({},t,{label:e.editable?/*#__PURE__*/i.default.createElement("span",null,e.schema.title," ",/*#__PURE__*/i.default.createElement(H,{className:"edit",onClick:e.onEdit,title:"Edit"},"Edit")):e.schema.title,onChange:function(t){return function(e,t,a){var r;r="checkbox"===e.target.type?e.target.checked:e.target.value,r=Array.isArray(r)?r.map(function(e){return g(e,t)}):g(r,t),a(e.target.name,r)}(t,e.schema.type,e.onChange)}}))}function Re(e){var t=e.data,a=e.schema,r=e.name,n=e.onChange,l=e.onRemove,o=e.removable,u=e.onKeyEdit,d=e.editable,p=e.onMoveUp,f=e.onMoveDown,m=e.parentType,h=e.errorMap,v=c(e,Ce);/*#__PURE__*/return i.default.createElement(be,{key:r,onRemove:o?function(e){return l(r)}:null,onMoveUp:p,onMoveDown:f},/*#__PURE__*/i.default.createElement(Ae,s({data:t,schema:a,name:r,onChange:n,onEdit:u,editable:d,parentType:m,errorMap:h},v)))}function Pe(e){var t=e.data,a=e.schema,r=e.name,n=e.onChange,l=e.onAdd,o=e.onRemove,u=e.onMove,d=e.onEdit,c=e.level,p=[],f=[],m=!0,h=S(a,"min_items","minItems")||0;t.length<=h&&(m=!1);var v=!0,g=S(a,"max_items","maxItems")||100;t.length>=g&&(v=!1),a.items.hasOwnProperty("$ref")&&(a.items=e.getRef(a.items.$ref));var y=k(a.items.type),E={schema:a.items,onChange:n,onAdd:l,onRemove:o,level:c+1,removable:m,onMove:u,onEdit:d,onKeyEdit:e.onKeyEdit,parentType:"array",getRef:e.getRef,errorMap:e.errorMap};if("multiselect"===E.schema.widget)E.data=t,E.name=r,E.removable=!1,E.onMoveUp=null,E.onMoveDown=null,v=!1,p.push(Re(E));else for(var b=function(n){E.data=t[n],E.name=O(r,n),E.onMoveUp=0===n?null:function(e){return u(O(r,n),O(r,n-1))},E.onMoveDown=n===t.length-1?null:function(e){return u(O(r,n),O(r,n+1))},"array"===y?f.push(Pe(E)):"object"===y?f.push(_e(E)):a.items.hasOwnProperty("oneOf")?f.push(/*#__PURE__*/i.default.createElement(Le,{parentArgs:e,nextArgs:s({},E),key:"oneOf_"+r+"_"+n})):a.items.hasOwnProperty("anyOf")?f.push(/*#__PURE__*/i.default.createElement(Te,{parentArgs:e,nextArgs:s({},E),key:"anyOf_"+r+"_"+n})):p.push(Re(E))},w=0;w0?"rjf-form-group-inner":""},C,x&&x.map(function(e,t){/*#__PURE__*/return i.default.createElement("div",{className:"rjf-error-text",key:t},e)}),f.map(function(e,t){/*#__PURE__*/return i.default.createElement("div",{className:"rjf-form-group-wrapper",key:"group_wrapper_"+r+"_"+t},/*#__PURE__*/i.default.createElement(Ee,{onRemove:m?function(e){return o(O(r,t))}:null,onMoveUp:t>0?function(e){return u(O(r,t),O(r,t-1))}:null,onMoveDown:t-1&&(b.required=!0);var x={data:y,schema:b,name:E,onChange:n,onAdd:l,onRemove:o,level:c+1,removable:N,onMove:u,onEdit:d,parentType:"object",getRef:e.getRef,errorMap:e.errorMap,onKeyEdit:function(){return function(e,t,a,r,n){var i=prompt("Rename key",t);if(null!==i&&(i=i.trim())!==t){if(!i)return alert("(!) Key name can't be empty.\r\n\r\n‎");if(e.hasOwnProperty(i))return alert("(!) Duplicate keys not allowed. This key already exists.\r\n\r\n‎");var l=w(r);l.pop(),l.push(i),n(a,l=O.apply(null,l),r)}}(t,g,y,E,d)}};x.editable=N,"array"===S?p.push(Pe(x)):"object"===S?p.push(_e(x)):x.schema.hasOwnProperty("oneOf")?p.push(/*#__PURE__*/i.default.createElement(Le,{parentArgs:e,nextArgs:s({},x),key:"oneOf_"+r+"_"+m})):x.schema.hasOwnProperty("anyOf")?p.push(/*#__PURE__*/i.default.createElement(Te,{parentArgs:e,nextArgs:s({},x),key:"anyOf_"+r+"_"+m})):p.push(Re(x))},y=0;y-1){e=n;break}if("object"===t){if(T(a.props.nextArgs.data,i)){e=n;break}}else if("array"===t){if(q(a.props.nextArgs.data,i)){e=n;break}}else if(t===l){e=n;break}}}else{var o=a.props.parentArgs.data,s=y(o),u=a.props.parentArgs.schema[a.schemaName];if(void 0===u)return e;for(var d=0;d-1||(d[c]=l[c]));u.forEach(function(e,t){d[e]=R(o[e],a.props.parentArgs.getRef)}),this.props.parentArgs.onChange(n,d)}},a.render=function(){var e,t=this.getSchema(),a=E(t),r=this.props.nextArgs?this.props.nextArgs:this.props.parentArgs;"object"===a?(e=_e,"object"==typeof r.data&&null!==r.data||(r.data={})):"array"===a?(e=Pe,Array.isArray(r.data)||(r.data=[])):(e=Re,r.removable=!1,r.onMoveUp=null,r.onMoveDown=null,(Array.isArray(r.data)||"object"==typeof r.data)&&(r.data=null));var n=e(s({},r,{schema:t})),l=null;return this.props.nextArgs&&(l=this.props.nextArgs.schema.title||null),/*#__PURE__*/i.default.createElement("div",{className:"rjf-form-group rjf-oneof-group"},/*#__PURE__*/i.default.createElement("div",{className:"rjf-oneof-selector"},/*#__PURE__*/i.default.createElement(oe,{value:this.state.option,options:this.getOptions(),onChange:this.handleChange,className:"rjf-oneof-selector-input",label:l})),n)},t}(i.default.Component);function Te(e){/*#__PURE__*/return i.default.createElement(Le,s({},e,{schemaName:"anyOf"}))}function qe(e){if(!(e instanceof Object))return{isValid:!1,msg:"Schema must be an object"};var t,a=E(e);return(t="object"===a?Fe(e):"array"===a?He(e):e.hasOwnProperty("allOf")?ze(e):e.hasOwnProperty("oneOf")?Ue(e):e.hasOwnProperty("anyOf")?Je(e):{isValid:!1,msg:"Outermost schema can only be of type array, list, object or dict"}).isValid&&e.hasOwnProperty("$defs")&&!e.$defs instanceof Object?{isValid:!1,msg:"'$defs' must be a valid JavaScript Object"}:t}function Fe(e){if(!(e.hasOwnProperty("keys")||e.hasOwnProperty("properties")||e.hasOwnProperty("oneOf")||e.hasOwnProperty("anyOf")||e.hasOwnProperty("allOf")))return{isValid:!1,msg:"Schema of type '"+e.type+"' must have at least one of these keys: ['properties' or 'keys' or 'oneOf' or 'anyOf' or 'allOf']"};var t,a=e.properties||e.keys;if(a&&(t=function(e){if(!(e instanceof Object))return{isValid:!1,msg:"The 'keys' or 'properties' key must be a valid JavaScript Object"};for(var t in e)if(e.hasOwnProperty(t)){var a=e[t];if(!(a instanceof Object))return{isValid:!1,msg:"Key '"+t+"' must be a valid JavaScript Object"};var r={isValid:!0},n=k(a.type);if(n?"object"===n?r=Fe(a):"array"===n&&(r=He(a)):r=a.hasOwnProperty("$ref")?$e(a):a.hasOwnProperty("oneOf")?Ue(a):a.hasOwnProperty("anyOf")?Je(a):a.hasOwnProperty("allOf")?ze(a):{isValid:!1,msg:"Key '"+t+"' must have a 'type' or a '$ref"},!r.isValid)return r}return{isValid:!0,msg:""}}(a),!t.isValid))return t;if(e.hasOwnProperty("additionalProperties")){if(!(e.additionalProperties instanceof Object)&&"boolean"!=typeof e.additionalProperties)return{isValid:!1,msg:"'additionalProperties' must be either a JavaScript boolean or a JavaScript object"};if(e.additionalProperties instanceof Object)if(e.additionalProperties.hasOwnProperty("$ref")){if(!(t=$e(e.additionalProperties)).isValid)return t}else{var r=k(e.additionalProperties.type);if("object"===r)return Fe(e.additionalProperties);if("array"===r)return qe(e.additionalProperties)}}return e.hasOwnProperty("oneOf")&&!(t=Ue(e)).isValid||e.hasOwnProperty("anyOf")&&!(t=Je(e)).isValid||e.hasOwnProperty("allOf")&&!(t=ze(e)).isValid?t:{isValid:!0,msg:""}}function He(e){if(!e.hasOwnProperty("items"))return{isValid:!1,msg:"Schema of type '"+e.type+"' must have a key called 'items'"};if(!(e.items instanceof Object))return{isValid:!1,msg:"The 'items' key must be a valid JavaScript Object'"};var t=k(e.items.type);if(t){if("object"===t)return Fe(e.items);if("array"===t)return He(e.items)}else{if(e.items.hasOwnProperty("$ref"))return $e(e.items);if(!e.items.hasOwnProperty("oneOf")&&!e.items.hasOwnProperty("anyOf")&&!e.items.hasOwnProperty("allOf"))return{isValid:!1,msg:"Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf'"}}return e.items.hasOwnProperty("oneOf")&&(validation=Ue(e.items),!validation.isValid)||e.items.hasOwnProperty("anyOf")&&(validation=Je(e.items),!validation.isValid)?validation:e.items.hasOwnProperty("allOf")?{isValid:!1,msg:"Currently, 'allOf' inside array items is not supported"}:{isValid:!0,msg:""}}function $e(e){return"string"!=typeof e.$ref?{isValid:!1,msg:"'$ref' keyword must be a string"}:e.$ref.startsWith("#")?e.$ref.lenght>1&&!e.$ref.startsWith("#/")?{isValid:!1,msg:"Invalid '$ref' path"}:{isValid:!0,msg:""}:{isValid:!1,msg:"'$ref' value must begin with a hash (#) character"}}function Ue(e){return Be(e,"oneOf")}function Je(e){return Be(e,"anyOf")}function ze(e){var t=Be(e,"allOf");if(!t.isValid)return t;for(var a=e.allOf,r=0;rparseInt(l)&&this.addError(a,"Maximum "+l+" items allowed."),N(e,"uniqueItems")&&("array"===n||"object"===n?t.length!==new Set(t.map(function(e){return JSON.stringify(e)})).size&&this.addError(a,"All items in this list must be unique."):t.length!==new Set(t).size&&this.addError(a,"All items in this list must be unique.")),o){var s=t.find(function(e){return-1===o.indexOf(e)});void 0!==s&&this.addError(a,'Invalid choice + "'+s+'"')}var u=this.getValidator(n);if(u||(r.hasOwnProperty("oneOf")?u=this.validateOneOf:r.hasOwnProperty("anyOf")?u=this.validateAnyOf:r.hasOwnProperty("anyOf")),u)for(var d=0;d-1&&(o.required=!0);var s=k(o.type),u=this.getValidator(s);if(!u)return void this.addError(a,'Unsupported type "'+s+'" for object properties (keys).');u(o,t[l],this.joinCoords([a,l]))}e.hasOwnProperty("allOf")&&this.validateAllOf(e,t,a)}}},this.validateAllOf=function(e,t,a){for(var r={type:"object",properties:{}},n=0;nparseInt(e.maxLength)&&this.addError(a,"This value may not be longer than "+e.maxLength+" characters."),k(e.format)){case"email":r=this.validateEmail;break;case"date":r=this.validateDate;break;case"time":r=this.validateTime;break;case"date-time":r=this.validateDateTime}r&&r.call(this,e,t,a)}}else this.addError(a,"This value is invalid. Must be a valid string.");else this.addError(a,"This field is required.")},this.validateBoolean=function(e,t,a){e.required&&null==t?this.addError(a,"This field is required."):"boolean"!=typeof t&&null!=t&&this.addError(a,"Invalid value.")},this.validateInteger=function(e,t,a){e.required&&null==t?this.addError(a,"This field is required."):null!==t&&("number"==typeof t&&t===parseInt(t)?this.validateNumber(e,t,a):this.addError(a,"Invalid value. Only integers allowed."))},this.validateNumber=function(e,t,a){e.required&&null==t?this.addError(a,"This field is required."):null!==t&&("number"==typeof t?((e.minimum||0===e.minimum)&&te.maximum&&this.addError(a,"This value must not be greater than "+e.minimum),(e.exclusiveMinimum||0===e.exclusiveMinimum)&&t<=e.exclusiveMinimum&&this.addError(a,"This value must be greater than "+e.exclusiveMinimum),(e.exclusiveMaximum||0===e.exclusiveMaximum)&&t>=e.exclusiveMaximum&&this.addError(a,"This value must be less than "+e.exclusiveMaximum),(e.multipleOf||0===e.multipleOf)&&100*t%(100*e.multipleOf)/100&&this.addError(a,"This value must be a multiple of "+e.multipleOf)):this.addError(a,"Invalid value. Only numbers allowed."))},this.validateEmail=function(e,t,a){t.indexOf(" ")>-1?this.addError(a,"Enter a valid email address."):t.length>320&&this.addError(a,"Email may not be longer than 320 characters")},this.validateDate=function(e,t,a){},this.validateTime=function(e,t,a){},this.validateDateTime=function(e,t,a){}}function et(e){this.containerId=e.containerId,this.dataInputId=e.dataInputId,this.schema=e.schema,this.data=e.data,this.errorMap=e.errorMap,this.fileHandler=e.fileHandler,this.fileHandlerArgs=e.fileHandlerArgs||{},this.eventListeners=null,this._dataSynced=!1,this.addEventListener=function(e,t){null===this.eventListeners&&(this.eventListeners={}),this.eventListeners.hasOwnProperty(e)||(this.eventListeners[e]=new Set),this.eventListeners[e].add(t)},this.onChange=function(e){this.data=e.data,this._dataSynced?this.eventListeners&&this.eventListeners.hasOwnProperty("change")&&this.eventListeners.change.size&&this.eventListeners.change.forEach(function(t){return t(e)}):this._dataSynced=!0},this.onChange=this.onChange.bind(this),this.render=function(){try{o.default.render(/*#__PURE__*/i.default.createElement(at,{schema:this.schema,dataInputId:this.dataInputId,data:this.data,errorMap:this.errorMap,fileHandler:this.fileHandler,fileHandlerArgs:this.fileHandlerArgs,onChange:this.onChange}),document.getElementById(this.containerId))}catch(e){o.default.render(/*#__PURE__*/i.default.createElement(rt,{error:e}),document.getElementById(this.containerId))}},this.update=function(e){this.schema=e.schema||this.schema,this.data=e.data||this.data,this.errorMap=e.errorMap||this.errorMap,this.render()},this.getSchema=function(){return this.schema},this.getData=function(){return this.data},this.validate=function(){return new Qe(this.getSchema()).validate(this.getData())}}var tt={},at=/*#__PURE__*/function(e){function t(t){var a;return(a=e.call(this,t)||this).populateDataInput=function(e){a.dataInput.value=JSON.stringify(e)},a.handleChange=function(e){a.setState({editorState:e})},a.state={editorState:Ke.create(t.schema,t.data)},a.prevEditorState=a.state.editorState,a.dataInput=document.getElementById(t.dataInputId),a}u(t,e);var a=t.prototype;return a.componentDidMount=function(){this.props.onChange({data:this.state.editorState.getData()}),this.populateDataInput(this.state.editorState.getData())},a.componentDidUpdate=function(e,t){if(this.props.schema===e.schema)this.props.data===e.data?(this.state.editorState!==t.editorState&&this.populateDataInput(this.state.editorState.getData()),this.props.onChange&&this.state.editorState!==t.editorState&&this.props.onChange({schema:this.state.editorState.getSchema(),data:this.state.editorState.getData(),prevSchema:t.editorState.getSchema(),prevData:t.editorState.getData()})):this.setState({editorState:Ke.update(this.state.editorState,this.props.data)});else{var a=this.props.schema,r=this.props.data!==e.data?this.props.data:this.state.editorState.getData();this.setState({editorState:Ke.create(a,r)})}},a.render=function(){/*#__PURE__*/return i.default.createElement(We,{editorState:this.state.editorState,onChange:this.handleChange,fileHandler:this.props.fileHandler,fileHandlerArgs:this.props.fileHandlerArgs,errorMap:this.props.errorMap})},t}(i.default.Component);function rt(e){/*#__PURE__*/return i.default.createElement("div",{style:{color:"#f00"}},/*#__PURE__*/i.default.createElement("p",null,"(!) ",e.error.toString()),/*#__PURE__*/i.default.createElement("p",null,"Check browser console for more details about the error."))}e.DataValidator=Qe,e.EditorState=Ke,e.ReactJSONForm=We,e.createForm=function(e){var t=new et(e);return tt[e.containerId]=t,t},e.getFormInstance=function(e){return tt[e]}}); diff --git a/dist/react-json-form.modern.js b/dist/react-json-form.modern.js index f91e401..e7bb98e 100644 --- a/dist/react-json-form.modern.js +++ b/dist/react-json-form.modern.js @@ -235,7 +235,7 @@ function getBlankArray(schema, getRef) { let type = normalizeKeyword(schema.items.type); if (!type) { - if (schema.items.hasOwnProperty['oneOf']) type = schema.items.oneOf[0];else if (schema.items.hasOwnProperty['anyOf']) type = schema.items.anyOf[0];else if (schema.items.hasOwnProperty['allOf']) type = schema.items.allOf[0]; + if (Array.isArray(schema.items['oneOf'])) type = getSchemaType(schema.items.oneOf[0]);else if (Array.isArray(schema.items['anyOf'])) type = getSchemaType(schema.items.anyOf[0]);else if (Array.isArray(schema.items['allOf'])) type = getSchemaType(schema.items.allOf[0]); } if (type === 'array') { @@ -245,6 +245,14 @@ function getBlankArray(schema, getRef) { } else if (type === 'object') { while (items.length < minItems) items.push(getBlankObject(schema.items, getRef)); + return items; + } else if (type === 'oneOf') { + while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef)); + + return items; + } else if (type === 'anyOf') { + while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef)); + return items; } @@ -3282,23 +3290,26 @@ function validateArray(schema) { } else { if (!schema.items.hasOwnProperty('oneOf') && !schema.items.hasOwnProperty('anyOf') && !schema.items.hasOwnProperty('allOf')) return { isValid: false, - msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf' or 'allOf'" + msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf'" }; } - if (schema.hasOwnProperty('oneOf')) { + if (schema.items.hasOwnProperty('oneOf')) { validation = validateOneOf(schema.items); if (!validation.isValid) return validation; } - if (schema.hasOwnProperty('anyOf')) { + if (schema.items.hasOwnProperty('anyOf')) { validation = validateAnyOf(schema.items); if (!validation.isValid) return validation; } - if (schema.hasOwnProperty('allOf')) { - validation = validateAllOf(schema.items); - if (!validation.isValid) return validation; + if (schema.items.hasOwnProperty('allOf')) { + // we don't support allOf inside array yet + return { + isValid: false, + msg: "Currently, 'allOf' inside array items is not supported" + }; } return { @@ -3360,13 +3371,18 @@ function validateSubschemas(schema, keyword) { keyword: one of 'oneOf' or 'anyOf' or 'allOf' Validation: 1. Must be an array - 2. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword + 2. Must have at least one subschema + 3. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword */ let subschemas = schema[keyword]; if (!Array.isArray(subschemas)) return { isValid: false, msg: "'" + keyword + "' property must be an array" }; + if (!subschemas.length) return { + isValid: false, + msg: "'" + keyword + "' must contain at least one subschema" + }; for (let i = 0; i < subschemas.length; i++) { let subschema = subschemas[i]; @@ -3752,6 +3768,14 @@ function DataValidator(schema) { let next_validator = this.getValidator(next_type); + if (!next_validator) { + if (next_schema.hasOwnProperty('oneOf')) { + next_validator = this.validateOneOf; + } else if (next_schema.hasOwnProperty('anyOf')) { + next_validator = this.validateAnyOf; + } else if (next_schema.hasOwnProperty('anyOf')) ; + } + if (next_validator) { for (let i = 0; i < data.length; i++) next_validator(next_schema, data[i], this.joinCoords([coords, i])); } else this.addError(coords, 'Unsupported type "' + next_type + '" for array items.'); diff --git a/dist/react-json-form.module.js b/dist/react-json-form.module.js index f91e401..e7bb98e 100644 --- a/dist/react-json-form.module.js +++ b/dist/react-json-form.module.js @@ -235,7 +235,7 @@ function getBlankArray(schema, getRef) { let type = normalizeKeyword(schema.items.type); if (!type) { - if (schema.items.hasOwnProperty['oneOf']) type = schema.items.oneOf[0];else if (schema.items.hasOwnProperty['anyOf']) type = schema.items.anyOf[0];else if (schema.items.hasOwnProperty['allOf']) type = schema.items.allOf[0]; + if (Array.isArray(schema.items['oneOf'])) type = getSchemaType(schema.items.oneOf[0]);else if (Array.isArray(schema.items['anyOf'])) type = getSchemaType(schema.items.anyOf[0]);else if (Array.isArray(schema.items['allOf'])) type = getSchemaType(schema.items.allOf[0]); } if (type === 'array') { @@ -245,6 +245,14 @@ function getBlankArray(schema, getRef) { } else if (type === 'object') { while (items.length < minItems) items.push(getBlankObject(schema.items, getRef)); + return items; + } else if (type === 'oneOf') { + while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef)); + + return items; + } else if (type === 'anyOf') { + while (items.length < minItems) items.push(getBlankOneOf(schema.items, getRef)); + return items; } @@ -3282,23 +3290,26 @@ function validateArray(schema) { } else { if (!schema.items.hasOwnProperty('oneOf') && !schema.items.hasOwnProperty('anyOf') && !schema.items.hasOwnProperty('allOf')) return { isValid: false, - msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf' or 'allOf'" + msg: "Array 'items' must have a 'type' or '$ref' or 'oneOf' or 'anyOf'" }; } - if (schema.hasOwnProperty('oneOf')) { + if (schema.items.hasOwnProperty('oneOf')) { validation = validateOneOf(schema.items); if (!validation.isValid) return validation; } - if (schema.hasOwnProperty('anyOf')) { + if (schema.items.hasOwnProperty('anyOf')) { validation = validateAnyOf(schema.items); if (!validation.isValid) return validation; } - if (schema.hasOwnProperty('allOf')) { - validation = validateAllOf(schema.items); - if (!validation.isValid) return validation; + if (schema.items.hasOwnProperty('allOf')) { + // we don't support allOf inside array yet + return { + isValid: false, + msg: "Currently, 'allOf' inside array items is not supported" + }; } return { @@ -3360,13 +3371,18 @@ function validateSubschemas(schema, keyword) { keyword: one of 'oneOf' or 'anyOf' or 'allOf' Validation: 1. Must be an array - 2. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword + 2. Must have at least one subschema + 3. If directly inside an object, each subschema in array must have 'properties' or 'keys keyword */ let subschemas = schema[keyword]; if (!Array.isArray(subschemas)) return { isValid: false, msg: "'" + keyword + "' property must be an array" }; + if (!subschemas.length) return { + isValid: false, + msg: "'" + keyword + "' must contain at least one subschema" + }; for (let i = 0; i < subschemas.length; i++) { let subschema = subschemas[i]; @@ -3752,6 +3768,14 @@ function DataValidator(schema) { let next_validator = this.getValidator(next_type); + if (!next_validator) { + if (next_schema.hasOwnProperty('oneOf')) { + next_validator = this.validateOneOf; + } else if (next_schema.hasOwnProperty('anyOf')) { + next_validator = this.validateAnyOf; + } else if (next_schema.hasOwnProperty('anyOf')) ; + } + if (next_validator) { for (let i = 0; i < data.length; i++) next_validator(next_schema, data[i], this.joinCoords([coords, i])); } else this.addError(coords, 'Unsupported type "' + next_type + '" for array items.'); diff --git a/package.json b/package.json index 1a7d4b8..9c0a6ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bhch/react-json-form", - "version": "2.7.0", + "version": "2.7.1", "description": "Create forms using JSON Schema", "publishConfig": { "access": "public"